feat: cria algoritmo que retorne uma lista com as palavras mais longas de uma lista de palavras.

This commit is contained in:
Emmanuel Vitor Pereira de Jesus 2022-10-31 14:01:49 -03:00
parent 5a8fa6be43
commit 6f3d088691

View File

@ -1,4 +1,15 @@
export function longestWords(words) { export function longestWords(words) {
// implementar logica aqui // implementar logica aqui
let longWords = [];
for (let i = 0; i < words.length; i++) {
if ((longWords.length === 0) || (words[i].length === longWords[0].length)) {
longWords.push(words[i]);
} else if (words[i].length > longWords[0].length) {
longWords = [];
longWords.push(words[i]);
}
}
return longWords;
} }