Return the length of the longest word in the provided sentence.
Your response should be a number.
Here are some helpful links:
function findLongestWord(str) {
var words = str.split(' ');
// --> my second solution
var lengthArr = words.map(wordsLength);
var max = Math.max(...lengthArr);
// --> my third solution
var reduceArr = lengthArr.reduce(reduceLength);
var reduceArr_2 = words.map(wordsLength).reduce( (a,b) => ( a > b ? a : b) );
function wordsLength(word){
return word.length;
}
function reduceLength(a, b) {
return (a > b ? a : b);
}
// --> my first solution
var highScore = 0;
for (var i = 0 ; i < words.length; i++) {
var score = words[i].length;
if( score > highScore) {
highScore = score;
}
}
console.log('RETURN HIGHSCORE => ', highScore );
overlay(highScore);
return highScore;
}