function findLongestOfThreeWords(word1, word2, word3) {
word1 = word1.split(' ');
word2 = word2.split(' ');
word3 = word3.split(' ');
var newArr = word1.concat(word2,word3);
var longestWord = [];
var longestWordLength = 0;
for(var i=0; i<newArr.length; i++) {
if(newArr[i].length > longestWordLength) {
longestWord = newArr[i];
longestWordLength = newArr[i].length;
}
}
return longestWord;
}
var result = findLongestOfThreeWords('these', 'three', 'words');
console.log(result); // --> 'these'
Stuck on a challenge with a longest of three words function -
"If there is a tie, it should return the first word in the tie."
Currently only getting 'words' returned instead of 'these'. The logic seems correct with longestWordLength = newArr[i].length; Any insight on this?