From 612643df7e9c7d397c1f5914e3e3a4a98cbc4947 Mon Sep 17 00:00:00 2001 From: Vinicius Date: Thu, 3 Nov 2022 01:13:58 -0200 Subject: [PATCH] feat(longestWords): adiciona ultima funcao do projeto --- 10-longestWords/index.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..eca2aee 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,18 @@ export function longestWords(words) { - // implementar logica aqui - -} \ No newline at end of file + // implementar logica aqui + let comp = 0; + let resultado = []; + for (i in text) { + if (comp < text[i].length) { + comp = text[i].length; + resultado.push(text[i]); + } + } + if (resultado.length > 1) { + if (resultado[0].length < resultado[1].length) { + resultado.shift(); + } + } + + return resultado; +}