CHALLENGE
const createMathOps = (base) => {
return {
add: (x) => base + x,
multiply: (x) => base * x
};
};
const createAdvancedMathOps = (base) => {
const basicOps = createMathOps(base);
return {
...basicOps,
square: () => basicOps.multiply(base),
addThenSquare: (x) => {
const added = basicOps.add(x);
return added * added;
}
};
};
const calculator = createAdvancedMathOps(5);
console.log(calculator.addThenSquare(3));
>>Click here to continue<<