Sorry for my dummy question, but I can’t understand why we should use other variable (longestWord)
in this example:
function findLongestWord(str) {
var array = str.split (" ");
var longestWord = 0;
for (var i = 0; i<array.length; i++)
if (longestWord < array[i].length)
{
longestWord = array[i].length;
}
return longestWord;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
and what is the logic? if longest word is smaller than length of my array, so make longest word equal to array element!?!?
WTF??
Thanks to everybody for your answers!