forked from M3-Academy/challenge-algorithms-v2.0
17 lines
465 B
JavaScript
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];
|
|
} |