Created
November 13, 2015 23:22
-
-
Save codebubb/8df73c593ee226b3cab4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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