Created
December 11, 2015 02:41
-
-
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
This file contains hidden or 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: @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