-
-
Save anonymous/c1251dd4ece8f82576aa to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/akiltipu 's solution for Bonfire: Find the Longest Word in a String
This file contains 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: @akiltipu | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-find-the-longest-word-in-a-string?solution=function%20findLongestWord(str)%20%7B%0A%20%20var%20max_len%20%3D%200%3B%0A%0A%20%20var%20new_str%20%3D%20str.split(%27%20%27)%3B%0A%20%20for%20(var%20i%20%3D%200%3B%20i%20%3C%20new_str.length%3B%20i%2B%2B)%7B%0A%09if(new_str%5Bi%5D.length%20%3E%20max_len)%7B%0A%09%09max_len%20%3D%20new_str%5Bi%5D.length%3B%0A%09%7D%0A%20%20%7D%0A%20%20return%20max_len%3B%0A%7D%0A%0AfindLongestWord(%22The%20quick%20brown%20fox%20jumped%20over%20the%20lazy%20dog%22)%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function findLongestWord(str) { | |
var max_len = 0; | |
var new_str = str.split(' '); | |
for (var i = 0; i < new_str.length; i++){ | |
if(new_str[i].length > max_len){ | |
max_len = new_str[i].length; | |
} | |
} | |
return max_len; | |
} | |
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