feat(longestWords): Adicionando algoritmo que retorna uma lista com as palavras mais longas de uma lista de palavras.

This commit is contained in:
Savio Carvalho Moraes 2022-10-30 15:32:45 -03:00
parent e5a5b59d9e
commit 57a410151f

View File

@ -1,4 +1,15 @@
export function longestWords(words) {
// implementar logica aqui
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;
}