challenge-algorithms-v2.0/07-sumEven/index.js
2022-11-02 19:29:06 -03:00

24 lines
688 B
JavaScript

export function sumEven(value) {
let soma = 0;
for (let i = 0; i < value.length; i++) {
if (value[i] % 2 === 0) {
soma += value[i];
}
}
return soma;
}
console.log(sumEven([]))//(0)
console.log(sumEven([1]))//(0)
console.log(sumEven([1, 2]))//(2)
console.log(sumEven([1, 2, 3]))//(2)
console.log(sumEven([1, 2, 3, 4]))//(6)
console.log(sumEven([1, 2, 3, 4, 5]))//(6)
console.log(sumEven([4, 6, 12, 5]))//(22)
console.log(sumEven([9, 234, 312, 999, 21, 2311]))//(546)
console.log(sumEven([533, 234, 23423, 32, 48876]))//(49142)
console.log(sumEven([-1, 5, -10, -45]))//(-10)
console.log(sumEven([-2, -7, -31]))//(-2)
console.log(sumEven([-2, 20, -31]))//(-18)