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

15 lines
428 B
JavaScript
Raw Normal View History

export function longestWords(words) {
// implementar logica aqui
let longWords = [];
for (let i = 0; i < words.length; i++) {
if ((longWords.length === 0) || (words[i].length === longWords[0].length)) {
longWords.push(words[i]);
} else if (words[i].length > longWords[0].length) {
longWords = [];
longWords.push(words[i]);
}
}
return longWords;
}