1 function findLongestWordLength(str) {
2 let words = str.split(' ');
3 let maxLength = 0;
4
5 for (let i = 0; i < words.length; i++) {
6 if (words[i].length > maxLength) {
7 maxLength = words[i].length;
8 }
9 }
10 return maxLength;
11 }
12
13
14findLongestWordLength("The quick brown fox jumped over the lazy dog");
15
16// 6
1function findLongestWordLength(str) {
2 return Math.max(...str.split(' ').map(word => word.length));
3}
1function findLongestWord(str) {
2 var longestWord = str.split(' ').sort(function(a, b) { return b.length - a.length; });
3 return longestWord[0].length;
4}
5findLongestWord("The quick brown fox jumped over the lazy dog");