美文网首页
Find the Longest Word in a Strin

Find the Longest Word in a Strin

作者: s1xteenth | 来源:发表于2017-03-12 20:44 被阅读0次

找到提供的句子中最长的单词,并计算它的长度。

函数的返回值应该是一个数字。

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

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

相关文章

网友评论

      本文标题:Find the Longest Word in a Strin

      本文链接:https://www.haomeiwen.com/subject/stsxnttx.html