The challenge is simple:
Return the length of the longest word in the provided sentence.
The solution is just as simple:
function findLongestWord(str) {
arr = str.split(' ');
size = 0;
for (var s in arr) {
if (arr[s].length > size) {
size = arr[s].length;
}
}
return size;
}
However, I vaguely remember you're not supposed to use for..in
in JavaScript unless absolutely necessary. What would be the more idiomatic approach for this loop?