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