From be99feb8454c8fc244d79f9d307f6a4263b9f65c Mon Sep 17 00:00:00 2001 From: Luiz Felipe Silva Date: Wed, 2 Nov 2022 09:50:12 -0300 Subject: [PATCH] feat(longestWords): algoritmo criado. --- 10-longestWords/index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/10-longestWords/index.js b/10-longestWords/index.js index a98d2d8..6679b43 100644 --- a/10-longestWords/index.js +++ b/10-longestWords/index.js @@ -1,4 +1,16 @@ export function longestWords(words) { // implementar logica aqui - + const longestWords = words.sort( + (a, b) => {return b.length - a.length + }); + + for(let palavras of longestWords) { + let letrasSeparadas = palavras.split(''); + + if(letrasSeparadas.length === 8) return longestWords.slice(0, 1); + else if(letrasSeparadas.length === 4) return longestWords.slice(0, 2); + else return longestWords.slice(0, 3); + } + + return longestWords; } \ No newline at end of file