feat(longestWords): Adiciona a logica do algoritmo que retorna uma lista com as palavras mais longas de uma lista de palavras

This commit is contained in:
Amanda de Almeida Fonseca 2022-10-28 15:36:48 -03:00
parent 83b587aa86
commit 96b864d058

View File

@ -1,4 +1,17 @@
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];
}