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 dbess1/a262b60ddbd893a210b5 to your computer and use it in GitHub Desktop.
Save dbess1/a262b60ddbd893a210b5 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/dbess1 's solution for Bonfire: Find the Longest Word in a String
// Bonfire: Find the Longest Word in a String
// Author: @dbess1
// 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 allWords = str.split(" ");
var biggestWords = 0;
for(var i = 0; i < allWords.length; i++){
if(allWords[i].length > biggestWords){
biggestWords = allWords[i].length;
}
}
return biggestWords;
}
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