This is my snippet. I feel this code satisfies the algorithm, but it does not pass. What could be the possible reason?
function findLongestWord(str, separator) {
var splitString = str.split(separator);
for (var i = 1; i <= splitString.length; i++) {
for (j = 1; j < splitString[i].length; j++) {
while (j === ' ') {
return j;
}
}
}
var greater;
if (j > greater) {
greater = j;
}
return greater;
}
findLongestWord("The quick brown fox jumped over the lazy dog", ' ');
greater
is never be assigned. 3.@Mohammed Raja has a complete answer of your code.