Write a function named getCurry
that receives one parameter:
callback
The function should return a new function that we'll be able to call like in the examples below.
PS: this function is similar with the currySum one
const sum = (...params) => {
let total = 0;
for (const arg of params) {
total += arg;
}
return total;
}
const currySum = getCurry(sum);
console.log(currySum()); // 0
console.log(currySum(1)()); // 1
console.log(currySum(1)(2)()); // 3
const diff = (...params) => {
let result = params[0] ?? 0;
for (let i = 1; i < params.length; i++) {
result -= params[i];
}
return result;
}
const curryDiff = getCurry(diff);
console.log(curryDiff()); // 0
console.log(curryDiff(1)(10)()); // -9
console.log(curryDiff(100)(10)(20)(30)()); // 40