From 5066f47f21fbe9fcbc42b6f8f94aea4fa27d8b1c Mon Sep 17 00:00:00 2001 From: Sabrina Miranda Date: Sat, 29 Oct 2022 01:12:57 -0300 Subject: [PATCH] feat: Implementa Desafio 2.10 --- 10-longestWords/index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..fdbce6c 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,14 @@ export function longestWords(words) { - // implementar logica aqui - + let palavras = [...words]; + let palavrasMaisLongas = [""]; + + for(let palavra of palavras) { + if(palavra.length > palavrasMaisLongas[0].length) { + palavrasMaisLongas = [palavra]; + }else if(palavra.length === palavrasMaisLongas[0].length) { + palavrasMaisLongas.push(palavra); + } + } + + return palavrasMaisLongas; } \ No newline at end of file