Skip to content

Instantly share code, notes, and snippets.

@piqueen314
Created December 11, 2015 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piqueen314/65871c8992eb60e19f6f to your computer and use it in GitHub Desktop.
Save piqueen314/65871c8992eb60e19f6f to your computer and use it in GitHub Desktop.
Return the length of the longest word in the provided sentence.
// Bonfire: Find the Longest Word in a String
// Author: @piqueen314
// 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 max=0;
for (var i=0; i < words.length; i++)
{
if(words[i].length>max)
{
max=words[i].length;
}
}
return max;
}
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