Tell us what’s happening:
I tried to solve the one of the basic algorithm problem about finding lonest word and returns a numer of that. It seems working but the last argument is not working well. I don’t understand why???
Your code so far
function findLongestWordLength(str) {
let arr = [];
str = str.split(" ");
for (let i=0; i < str.length; i++) {
arr += str[i].length;
}
return Math.max(...arr);
}
findLongestWordLength("The quick brown fox jumped over the lazy dog");
function findLongestWordLength(str) {
let arr = [];
str = str.split(" ");
for (let i=0; i < str.length; i++) {
arr += str[i].length;
}
return Math.max(...arr);
}
findLongestWordLength("The quick brown fox jumped over the lazy dog");
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36
.
Challenge: Find the Longest Word in a String
Link to the challenge: