题目
返回给出的句子中最长的单词的长度。
你的返回应该是一个数字。
要求
findLongestWordLength("The quick brown fox jumped over the lazy dog")
应该返回一个数字。findLongestWordLength("The quick brown fox jumped over the lazy dog")
应该返回 6。findLongestWordLength("May the force be with you")
应该返回 5。findLongestWordLength("Google do a barrel roll")
应该返回 6。findLongestWordLength("What is the average airspeed velocity of an unladen swallow")
应该返回 8。findLongestWordLength("What if we try a super-long word such as otorhinolaryngology")
应该返回 19。
代码
function findLongestWordLength(str) {
let strArr = str.split(' ')
let temp = strArr[0]
for(let i = 1;i < strArr.length;i++) {
temp.length < strArr[i].length ? temp = strArr[i] :''
}
return temp.length;
}
findLongestWordLength("The quick brown fox jumped over the lazy dog");