feat(longestWords): algoritmo criado.

This commit is contained in:
Luiz Felipe Silva 2022-11-02 09:50:12 -03:00
parent e155699ab6
commit be99feb845

View File

@ -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;
}