From 56904fc6424d9a5f000f102416d7741ff62cbdfc Mon Sep 17 00:00:00 2001 From: WellingtonWDS Date: Tue, 1 Nov 2022 09:38:13 -0300 Subject: [PATCH] feat(longestWords): Implementacao da funcao longestWords() --- 10-longestWords/index.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..6b15947 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,19 @@ export function longestWords(words) { - // implementar logica aqui + let maiorPalavra = 0; + let maiores = []; + + for (let i = 0; i < words.length; i++){ + if(words[i].length > maiorPalavra){ + maiorPalavra = words[i].length + } + } + + for (let i = 0; i < words.length; i++){ + if(words[i].length === maiorPalavra){ + maiores.push(words[i]); + } + } + + return maiores; } \ No newline at end of file