Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexandrebvd/4c7431e9e27d8b29aebd to your computer and use it in GitHub Desktop.
Save alexandrebvd/4c7431e9e27d8b29aebd to your computer and use it in GitHub Desktop.
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