Find the Longest Word in a String
so1)
function findLongestWordLength(str) {
let arr = str.split(' ')
let arr2 = []
for(let a of arr){
arr2.push(a.length)
}
return Math.max(...arr2)
}
findLongestWordLength("The quick brown fox jumped over the lazy dog");
sol2)
function findLongestWordLength(str) {
let arr = str.split(' ')
let max = 0
for (let a of arr){
if(a.length >= max){
max = a.length
}
}
return max
return str.length;
}
findLongestWordLength("The quick brown fox jumped over the lazy dog");