My teacher asked us to try and build a function that finds the longest length of a word in a string without using the str.split() method. the function should take a string as a parameter and and output the length of the longest word.
so far I have tried to make a function that puts the string into an array using the .push method then try to break up that array into each individual word and find the length of each word in each sub array and compare then. Because I am not smart or experienced enough to do this a friend of mine told me to try and :
> "just use two “tracking” variables. One to keep track of the current word and one to keep track of the longest word seen so far I will let you think about the initial values of what these should be. Next, it is just a matter of iterating through each character of str (strings are iterable just like arrays) to “build” a word. When you come across a space character or then end of str you know you have a complete word. You compare the length of this word with the current longest word (your other tracking variable) and assign the larger of the two to your longest word tracking variable. At the very end of the iteration your longest word tracking variable will contain the longest word length which you can return.Note: You will need to reset the word variable after you check it’s length, so it does not continue “building” through the rest of the iteration." >
I'm not really sure what he means or what to do.
so far I have this :
function findLongestWordLength(str) {
let words = []
words.push(str);
console.log(words)
}
findLongestWordLength("The quick brown fox jumped over the lazy dog");
what should I do ? I have the string pushed to an array but now that my friend has given me a hint I'm not sure what to do.