I am trying to implement currying pattern for sum multiplication in my simple program. For that, I have defined one generic curry function and calling sum and multiply functions in it but I am not getting any output. can anyone tell me what's wrong in my program? Thanks in advance.
code ::
function curry(fn) {
sum.call(this, a,b);
multiply.call(this, a,b,c);
}
function sum(a, b) {
return a + b;
}
function multiply(a, b, c) {
return a * b * c;
}
const curriedSum = curry(sum);
const curriedMult = curry(multiply);
const addOne = curriedSum(1);
const addTwo = curriedSum(2);
Expected Output ::
// 1 + 3 = 4
console.log('result', addOne(3)); // 'result' 4
// 1 + 1 = 2
console.log('result', addOne(1)); // 'result' 2
// 2 + 5 = 7
console.log('result', addTwo(5)); // 'result' 7
// 2 * 3 * 4 = 24
console.log('result', curriedMult(2)(3)(4)); // 'result' 24