From c6755fb75fa4ce8bf0986951bc43e8766a15a577 Mon Sep 17 00:00:00 2001 From: ThiagoDuutra Date: Sun, 30 Oct 2022 13:47:20 -0300 Subject: [PATCH] feat: resolvido questao longestWords --- 10-longestWords/index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..4951c72 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,10 @@ export function longestWords(words) { - // implementar logica aqui - -} \ No newline at end of file + // implementar logica aqui + //1º: Obter o tamanho do primeiro elemento do índice + let maxWords = words[0].length; + //2º: Percorrer o array para achar o maior elemento usando a função Math.max() + words.map((mapear) => (maxWords = Math.max(maxWords, mapear.length))); + //3ª: Criando um novo array para receber os maiores valores dentro desse array + let newArray = words.filter((mapear) => mapear.length == maxWords); + return newArray; +}