From ecf880dc2fc12273f41cf1a175f6de5ae6e7049e Mon Sep 17 00:00:00 2001 From: HenriqueSSan Date: Thu, 27 Oct 2022 22:01:20 -0300 Subject: [PATCH] feat(challenge-10): completed challenge --- 10-longestWords/index.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..2153892 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,21 @@ export function longestWords(words) { - // implementar logica aqui - -} \ No newline at end of file + // implementar logica aqui + if (words.length === 0 || !words) return 0; + + let wordLengthMax = 0; + let wordsList = []; + + for (let word of words) { + if (word.length >= wordLengthMax) { + wordLengthMax = word.length; + } + } + + for (let word of words) { + if (wordLengthMax === word.length) { + wordsList.push(word); + } + } + + return wordsList; +}