challenge-algorithms-v2.0-c.../07-sumEven/index.js

15 lines
402 B
JavaScript
Raw Normal View History

export function sumEven(value) {
// implementar logica aqui
2022-10-30 22:45:47 +00:00
let pares = []
for (let i = 0; i < value.length; i++) {
if (value[i] % 2 == 0) {
pares.push(value[i])
}
}
2022-10-31 17:56:24 +00:00
let total = 0
2022-10-30 22:45:47 +00:00
for (let i = 0; i < pares.length; i++) {
total += pares[i]; // adiciona o valor do indice (que aumenta com o loop) no total
}
value = [];
return total; // torna value = total
}