Skip to content

Instantly share code, notes, and snippets.

@piqueen314 piqueen314/gist3
Created Dec 11, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.