Quotes help make search much faster. Example: "Practice Makes Perfect"

Friday, May 12, 2017

FreeCodeCamp Find The Longest Word In A String Sample Solution



function findLongestWord(str) {
  var arr = str.split(' ');
  var longest = "";
  for(var i=0; i<arr.length; i++){
    if(arr[i].length > longest.length){
      longest = arr[i];
    }
  }
  return longest.length;
}

findLongestWord("The quick brown fox jumped over the lazy dog");

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts