const Calc = {
sum: (...arg) => arg.reduce((acc, num) => acc + num, 0),
sub: (...arg) => arg.reduce((acc, num) => acc - num),
mul: (...arg) => arg.reduce((acc, num) => acc * num, 1),
div: (...arg) => arg.reduce((acc, num) => acc / num),
}
const num1 = 10;
const num2 = 5;
console.log({num1, num2});
console.log(`Sum: ${Calc.sum(...Object.values({num1, num2}))}`);
console.log(`Sub: ${Calc.sub(num1, num2)}`);
console.log(`Mul: ${Calc.mul(1, 2, 3, 4, 5)}`);
console.log(`Div: ${Calc.div(10,5)}`);
Created
December 11, 2024 13:24
-
-
Save felipejoq/5b8d3f891d5bef479ef0873ae1eed749 to your computer and use it in GitHub Desktop.
An object with calculator flex for basic operations maths
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usando reduce para generar una calculadora con las 4 operaciones básicas