From f577fc0a57f97b9e22391950a2847e511ff06f5b Mon Sep 17 00:00:00 2001 From: wellington carlos Date: Wed, 2 Nov 2022 14:52:14 -0300 Subject: [PATCH] (feat) finalizando o teste 10-longestWords --- 10-longestWords/index.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..377fa39 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,24 @@ export function longestWords(words) { - // implementar logica aqui - -} \ No newline at end of file + + let letra = words + let tamanho = 0 + let maximo = [' '] + + for (let i = 0; i < letra.length; i++) { + if (letra[i].length >= tamanho) { + tamanho = letra[i].length + if (maximo[maximo.length - 1].length < letra[i].length) { + maximo = [] + maximo.push(letra[i]) + } + else { + maximo = [...maximo, letra[i]] + } + } + } + return [...maximo] +} + + + +