So my solution seems to work but only when I comment out the actual function call
Your code so far
let myRegex = /\w+/gi;
let emptyArr= [];
let upCounter = 0;
function findLongestWordLength(str) {
let result = str.match(myRegex);
for (let i=0; i<= result.length -1; i++){
emptyArr.push(result[i].length)
}
for (let j=0; j < emptyArr.length; j++) {
if (upCounter < emptyArr[j]){
upCounter = emptyArr[j];
}
}
return upCounter;
}
findLongestWordLength("The quick brown fox jumped over the lazy dog");
My issue is that it only clears me when i comment out the pre-installed function call as such
//findLongestWordLength("The quick brown fox jumped over the lazy dog");
Otherwise it throws me a fail on condition three - longest word in "May the Force be With you" (max length 5)
i suspect my upCounter is not resetting between the first test case (leaving it at 6)
and refusing to accept the second case, since the inbuild function call is already at 6. Does the upCounter =0; just need to be placed somewhere else? i've tried to move it around to re-initialize it between runs, but it dosen't seem to work out for me.
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36
.
Challenge: Find the Longest Word in a String
Link to the challenge: