https://www.freecodecamp.cn/challenges/find-the-longest-word-in-a-string

知识点

Array.prototype.reduce()

function findLongestWord(str) {
  var arr= str.replace(/[^A-Za-z\s]/g,"").split(" ");
 var longestWord=arr.reduce(function(prev,curr){
   return prev.length>curr.length?prev:curr;
 },"");
  
  return longestWord.length;
}

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


Demi_YuHongJun

Demi的随笔和技术空间