challenge-algorithms-v2.0-S.../10-longestWords/index.js

16 lines
425 B
JavaScript
Raw Normal View History

export function longestWords(words) {
let vetWords = [];
for (let index = 0; index < words.length; index++) {
if (vetWords.length === 0) {
vetWords.push(words[index]);
} else if (vetWords[0].length < words[index].length) {
vetWords = [];
vetWords.push(words[index]);
} else if (vetWords[0].length === words[index].length) {
vetWords.push(words[index]);
}
}
return vetWords;
}