Skip to content

Instantly share code, notes, and snippets.

Created November 27, 2015 21:12
Show Gist options
  • Save anonymous/3b3e7561994efd650016 to your computer and use it in GitHub Desktop.
Save anonymous/3b3e7561994efd650016 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/vadimbrodsky 's solution for Bonfire: Find the Longest Word in a String
// Bonfire: Find the Longest Word in a String
// Author: @vadimbrodsky
// 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) {
return str.toLowerCase().split(' ').sort(function(a, b) {
if (a.length < b.length) {
return 1;
} else if (a.length > b.length) {
return -1;
} else {
return 0;
}
})[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