http://www.freecodecamp.com/twhite96 's solution for Bonfire: Find the Longest Word in a String
// Bonfire: Find the Longest Word in a String
// Author: @twhite96
// Challenge: http://www.freecodecamp.com/challenges/bonfire-find-the-longest-word-in-a-string
function findLongestWord(str) {
var words = str.split(' ');
var longest = 0;
for (var i = 0; i < words.length; i++) {
if (words[i].length > longest) {
longest = words[i].length;
}
}
return longest;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
// Bonfire: Find the Longest Word in a String
// Author: @twhite96
// Challenge: http://www.freecodecamp.com/challenges/bonfire-find-the-longest-word-in-a-string?solution=function%20findLongestWord(str)%20%7B%0A%20%20var%20words%20%3D%20str.split(%27%20%27)%3B%0A%20%0A%20%20var%20longest%20%3D%200%3B%0A%20%20%0A%20%20for%20(var%20i%20%3D%200%3B%20i%20%3C%20words.length%3B%20i%2B%2B)%20%7B%0A%20%20%20%20if%20(words%5Bi%5D.length%20%3E%20longest)%20%7B%0A%20%20%20%20%20%20longest%20%3D%20words%5Bi%5D.length%3B%0A%20%20%20%20%7D%0A%20%20%20%20%0A%20%20%7D%0A%20%20%0A%20%20%20%20%20%20return%20longest%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 words = str.split(' ');
var longest = 0;
for (var i = 0; i < words.length; i++) {
if (words[i].length > longest) {
longest = words[i].length;
}
}
return longest;
}
findLongestWord("The quick brown fox jumped over the lazy dog");