Desafio 7 atualizado

This commit is contained in:
matheusjardimgarcia 2022-10-31 21:23:09 -03:00
parent 37a17e6d9e
commit 145f75e822

View File

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