Tell us what’s happening:
I don’t know if any built in functions available for this but i tried to do the challenge my way and this is what i got. The code is working fine for every string except for “What if we try a super-long word such as otorhinolaryngology” Help Me guys
Your code so far
function findLongestWordLength(str) {
let long=0;
let curr=0;
for (let i=0;i<str.length;i++){
if(str[i]==' '){
if(curr>=long){
long=curr;
curr=0;
}
else{
curr=0;
}
}
else{
curr=curr+1;
}
}
console.log(long);
return long;
}
findLongestWordLength("The quick brown fox jumped over the lazy dog");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/find-the-longest-word-in-a-string