From 5b864a141734f85fd41baf44d077237f69cd113a Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 2 Nov 2022 13:41:20 -0300 Subject: [PATCH] feat: criando o algoritmo para a lista com as palavras longas --- 10-longestWords/index.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..deef95f 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,27 @@ export function longestWords(words) { - // implementar logica aqui - + // implementar logica aqui + const lengthArray = [] + + words.forEach(element => { + lengthArray.push([element, element.length ]) + }) + + + let res = ['', 0] + + lengthArray.forEach(array => { + if (res[1] < array[1]) { + res = array + } + }) + + const AllLongestWords = [] + + lengthArray.forEach(array => { + if (res[1] == array[1]) { + AllLongestWords.push(array[0]) + } + }) + + return AllLongestWords } \ No newline at end of file