2022-10-27 15:07:13 +00:00
|
|
|
export function sum(values) {
|
2022-11-02 18:50:28 +00:00
|
|
|
let soma = 0;
|
|
|
|
for (let index = 0; index < values.length; index += 1) {
|
|
|
|
soma = soma + values[index];
|
|
|
|
}
|
|
|
|
return soma;
|
|
|
|
}
|
|
|
|
console.log(sum([])); //(0)
|
|
|
|
console.log(sum([1])); //(1)
|
|
|
|
console.log(sum([1, 2])); //(3)
|
|
|
|
console.log(sum([1, 2, 3])); //(6)
|
|
|
|
console.log(sum([1, 2, 3, 4])); //(10)
|
|
|
|
console.log(sum([1, 2, 3, 4, 5])); //(15)
|
|
|
|
console.log(sum([4, 6, 12, 5])); //(27)
|
|
|
|
console.log(sum([9, 234, 312, 999, 21, 2311])); //(3886)
|
|
|
|
console.log(sum([533, 234, 23423, 32, 48876])); //(73098)
|
|
|
|
console.log(sum([-1, 5, -10, -45]))//(-51)
|
|
|
|
console.log(sum([-2, -7, -31]))//(-40)
|