From 57a410151f93c4939ae651bfe9156df018aecbb4 Mon Sep 17 00:00:00 2001 From: Savio Date: Sun, 30 Oct 2022 15:32:45 -0300 Subject: [PATCH] feat(longestWords): Adicionando algoritmo que retorna uma lista com as palavras mais longas de uma lista de palavras. --- 10-longestWords/index.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..9b07942 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,15 @@ export function longestWords(words) { - // implementar logica aqui - -} \ No newline at end of file + let vetWords = []; + + for (let index = 0; index < words.length; index++) { + if (vetWords.length === 0) { + vetWords.push(words[index]); + } else if (vetWords[0].length < words[index].length) { + vetWords = []; + vetWords.push(words[index]); + } else if (vetWords[0].length === words[index].length) { + vetWords.push(words[index]); + } + } + return vetWords; +}