Tell us what’s happening:
I’m trying to find the longest word in an array, this is what I’ve written so far (please do not laugh) but it works for some texts but not all. Why?
Your code so far
function findLongestWordLength(str) {
let strSplit = []
strSplit = str.split(' ');
let length = strSplit.map(word => {
return word.length;
});
let strLength = length.sort();
let lastEle = strLength[strLength.length-1];
return lastEle;
}
findLongestWordLength("The quick brown fox jumped over the lazy dog");
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.135 Safari/537.36.