Skip to content

Instantly share code, notes, and snippets.

Created December 5, 2015 12:54
Show Gist options
  • Save anonymous/311f2540c1cb0fe5075c to your computer and use it in GitHub Desktop.
Save anonymous/311f2540c1cb0fe5075c to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/bskydive 's solution for Bonfire: Find the Longest Word in a String
// Bonfire: Find the Longest Word in a String
// Author: @bskydive
// 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 strToMasSorted=str.split(' ').sort(function compare(a,b){return a.length-b.length;});
return strToMasSorted[strToMasSorted.length-1].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