function findLongestWordLength(str) {
const arr = str.split(" ");
console.log(arr)
let longmax = 0;
for (let i = 0 ; i < arr.length -1 ; i++){
if (arr[i].length > arr[i+1].length){
longmax = arr[i].length;
}else if(arr[i].length <= arr[i+1].length){
longmax = arr[i+1].length;
}
}
return longmax;
}
findLongestWordLength("The quick brown fox jumped over the lazy dog");
console.log(findLongestWordLength("The quick brown fox jumped over the lazy dog"))
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36 Edg/89.0.774.45.
you are always confronting two consecutive words in the string and picking the longest, which means that at the end you get the length of the longest between the last two words, not in general
you are doing the equivalent of