Skip to content

Instantly share code, notes, and snippets.

Created December 11, 2015 02:41
Show Gist options
  • Save anonymous/7ed22fd6584b027821a8 to your computer and use it in GitHub Desktop.
Save anonymous/7ed22fd6584b027821a8 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/thetinybeaker 's solution for Bonfire: Find the Longest Word in a String
// Bonfire: Find the Longest Word in a String
// Author: @thetinybeaker
// 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(' ');
var numbers = [];
// return words[9].length;
for (i = 0; i < words.length; i++) {
var wordLength = words[i].length;
numbers.push(wordLength);
}
return Math.max.apply(Math, numbers);
}
findLongestWord("What if we try a super-long word such as otorhinolaryngology");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment