Skip to content

Instantly share code, notes, and snippets.

@mmloveaa
Created April 4, 2016 17:38
Show Gist options
  • Select an option

  • Save mmloveaa/1f0fa59f7c77e350e393902c69f05dd0 to your computer and use it in GitHub Desktop.

Select an option

Save mmloveaa/1f0fa59f7c77e350e393902c69f05dd0 to your computer and use it in GitHub Desktop.
4-4 freecodecamp Q4
Return the length of the longest word in the provided sentence.
Your response should be a number.
Remember to use Read-Search-Ask if you get stuck. Write your own code.
function findLongestWord(str) {
var arr = str.split(' ');
var max=0;
for(var i=0; i<arr.length; i++){
if(arr[i].length > max) {
max=arr[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