From c7e515ec35d0acb01c048832b24d5c7a1e935213 Mon Sep 17 00:00:00 2001 From: WillSimao Date: Mon, 31 Oct 2022 16:55:29 -0300 Subject: [PATCH] feat(longestWords): Finaliza algoritmo --- 10-longestWords/index.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..9134806 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,26 @@ export function longestWords(words) { // implementar logica aqui - -} \ No newline at end of file + + let longestLength = 0; + let longestWords = []; + + words.forEach(word => { + if (longestLength < word.length) { + longestLength = word.length; + } else { + longestLength; + } + + }); + + words.forEach(word => { + if (word.length === longestLength) { + longestWords.push(word); + } + }); + + return longestWords; + } + + +