Created
December 11, 2015 01:43
-
-
Save piqueen314/65871c8992eb60e19f6f to your computer and use it in GitHub Desktop.
Return the length of the longest word in the provided sentence.
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: @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