I have written this piece of code for the “Basic Algorithm Scripting: Find the Longest Word in a String” - assignment. It works on all but one of the tests. It does pass the test, if I try it in my own editor.
I can’t seem to figure out what is wrong, please help!!
let strArray;
let numArray = [];
function findLongestWordLength(str) {
strArray = str.split(' ');
for(let i = 0; i < strArray.length; i++){
numArray.push(strArray[i].length);
}
return Math.max(...numArray);
}
findLongestWordLength("May the force be with you");