rabbitrun
9/5/2016 - 2:34 AM

Find longest word in a string.

Find longest word in a string.

function findLongestWord(str) {
  var strArray = str.split(" "),
      arrCount = [];
  for (var i = 0; i < strArray.length; i++) {
    arrCount.push(strArray[i].length);
  }
  return Math.max(...arrCount);
}

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