suma argumentów JavaScript
const sum = (...input) => {
input.reduce((a, b) => a + b)
}
// Example
sum(1, 2, 3, 4)
//output
10
Code_Breaker
const sum = (...input) => {
input.reduce((a, b) => a + b)
}
// Example
sum(1, 2, 3, 4)
//output
10
x = sumAll(1, 123, 500, 115, 44, 88);
function sumAll() {
let sum = 0;
for (let i = 0; i < arguments.length; i++) {
sum += arguments[i];
}
return sum;
}
const sum = (...args) => args.reduce((a, b) => a + b);
// Example
sum(1, 2, 3, 4); //10