Skip to content

Instantly share code, notes, and snippets.

Created December 9, 2015 04:12
Show Gist options
  • Select an option

  • Save anonymous/e79827c4385c2c0bfa2f to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/e79827c4385c2c0bfa2f to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/fcc3b5ed711 's solution for Bonfire: Find the Longest Word in a String
// Bonfire: Find the Longest Word in a String
// Author: @fcc3b5ed711
// 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(' ');
str = words[0];
words.forEach(function(e, i) {
if (e.length > str.length)
str = e;
});
return str.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