一个 句子 由一些 单词 以及它们之间的单个空格组成,句子的开头和结尾不会有多余空格。
给你一个字符串数组 sentences ,其中 sentences[i] 表示单个 句子 。
请你返回单个句子里 单词的最多数目
例如:输入:sentences = [“alice and bob love leetcode”, “i think so too”, “this is great thanks very much”]
输出:6
let sentences = ["alice and bob love leetcode", "i think so too", "this is great thanks very much"]
const mostWordsFound = sentences => {
// let max = -1;
// const len = sentences.length;
// for (let i = 0; i < len; i++) {
// const count = sentences[i].split(' ').length;
// max = Math.max(max, count);
// }
// return max;
console.log( ...sentences.map(item=>
item.split(' ').length
))
return Math.max(...sentences.map(item => item.split(' ').length))
};
console.log(mostWordsFound(sentences))