Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
6.Bonfire: Find the Longest Word in a String
function findLongestWord(str) {
str = str.split(' ');
var longestWord = '';
console.log(str);
for (var i in str) {
if (str[i].length >= longestWord.length) {
longestWord = str[i];
console.log(longestWord);
}
}
return longestWord.length;
}
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