From 96b864d058139d978091c2ee81fee8e0cb32acbb Mon Sep 17 00:00:00 2001 From: amanda almeida Date: Fri, 28 Oct 2022 15:36:48 -0300 Subject: [PATCH] feat(longestWords): Adiciona a logica do algoritmo que retorna uma lista com as palavras mais longas de uma lista de palavras --- 10-longestWords/index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..99d6ff7 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -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]; } \ No newline at end of file