Skip to content

Instantly share code, notes, and snippets.

@codebubb
Created November 13, 2015 23:22
Show Gist options
  • Save codebubb/8df73c593ee226b3cab4 to your computer and use it in GitHub Desktop.
Save codebubb/8df73c593ee226b3cab4 to your computer and use it in GitHub Desktop.
// Bonfire: Find the Longest Word in a String
// Author: @codebubb
// Challenge: http://www.freecodecamp.com/challenges/bonfire-find-the-longest-word-in-a-string?solution=function%20findLongestWord(str)%20%7B%0A%20%20return%20str.split(%27%20%27).sort(function(a%2Cb)%7B%0A%20%20%20%20return%20a.length%20%3C%20b.length%3B%0A%20%20%7D)%5B0%5D.length%3B%0A%7D%0A%0AfindLongestWord(%22The%20quick%20brown%20fox%20jumped%20over%20the%20lazy%20dog%22)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function findLongestWord(str) {
return str.split(' ').sort(function(a,b){
return a.length < b.length;
})[0].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