bugfix(longestWords): corrige o codigo

This commit is contained in:
Vinicius 2022-11-09 19:19:19 -02:00
parent 3c9a57e29d
commit 3e4e690a07

View File

@ -1,16 +1,16 @@
export function longestWords(words) {
// implementar logica aqui
let comp = 0;
let maiorTamanho = 0;
let i = 0;
let resultado = [];
for (i in words) {
if (comp < words[i].length) {
comp = words[i].length;
resultado.push(words[i]);
if (words[i].length > maiorTamanho) {
maiorTamanho = words[i].length;
}
}
if (resultado.length > 1) {
if (resultado[0].length < resultado[1].length) {
resultado.shift();
for (i in words) {
if (words[i].length == maiorTamanho) {
resultado.push(words[i]);
}
}