Skip to content

Instantly share code, notes, and snippets.

@mtroiani
Created December 11, 2015 22:13
Show Gist options
  • Save mtroiani/55ec5bf1c1cf83ffc814 to your computer and use it in GitHub Desktop.
Save mtroiani/55ec5bf1c1cf83ffc814 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/mtroiani 's solution for Bonfire: Find the Longest Word in a String
// Bonfire: Find the Longest Word in a String
// Author: @mtroiani
// 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 arrayOfStrings = str.split(" ");
var maxLength = 0;
for (var i=0; i < arrayOfStrings.length; i++) {
if (arrayOfStrings[i].length > maxLength) {
maxLength = arrayOfStrings[i].length;
}
}
return maxLength;
}
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