1

I have to call function in below way

sum(3)(2)

My function is:

sum(a,b) { return a + b }
  • Does this answer your question? [javascript currying](https://stackoverflow.com/questions/5273420/javascript-currying) – sylvanaar May 14 '20 at 05:44

2 Answers2

4

Take a look at Currying concept

let sum = (a) => (b) => a + b

console.log(sum(1)(3)) // 4
Soham
  • 705
  • 3
  • 19
0

you can try out this approach

function sum(x, y) {
 if (y !== undefined) {
  return x + y;
 } else {
  return function(y) { return x + y; };
 }
}

To understand it better https://www.toptal.com/javascript/interview-questions

kokila
  • 294
  • 2
  • 8