function findLongestWord(str) {
var arr = [];
arr = str.split(" ");
str = arr[0];
for(var i = 0; i < arr.length; i++) {
if(arr[i].length > str.length) {
str = arr[i];
}
}
return str.length;
}
findLongestWord("The quick brown fox jumped over the lazy dog"); //6
function findLongestWord(str) {
var arr = [];
arr = str.split(" ");
for(var i = 0; i < arr.length; i++) {
str = arr[0];
if(arr[i].length > str.length) {
str = arr[i];
}
}
return str.length;
}
findLongestWord("The quick brown fox jumped over the lazy dog"); //3
为什么是3?
富国沪深
相关分类