Skip to content

Instantly share code, notes, and snippets.

Created December 7, 2015 09:32
Show Gist options
  • Save anonymous/b87f1f43237bae66683f to your computer and use it in GitHub Desktop.
Save anonymous/b87f1f43237bae66683f to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/patrickcurl 's solution for Bonfire: Find the Longest Word in a String
// Bonfire: Find the Longest Word in a String
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-find-the-longest-word-in-a-string#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function findLongestWord(str) {
var words = str.split(" ");
var longestWord = words[0];
for(i=0;i<words.length;i++){
if(words[i].length > longestWord.length){
longestWord = words[i];
}
}
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