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

17 lines
465 B
JavaScript

export function longestWords(words) {
// implementar logica aqui
let size = 0;
let longest = [""];
for (let word of words) {
if (word.length >= size) {
size = word.length;
if (longest[longest.length - 1].length < word.length) {
longest = [];
longest.push(word);
} else {
longest = [...longest, word];
}
}
}
return [...longest];
}