Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Return the length of the longest word in the provided sentence.
function findLongestWord(str) {
var strArray = str.toUpperCase().split(' ').sort();
var longest = 0;
for (var i = 0; i < strArray.length; i++) {
if (strArray[i].length > longest) {
longest = strArray[i].length;
}
}
return longest;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.