0

How do I write a function which can be called several times in a row with one parameter? Here is an example:

function sum(a) {
// what should here?
}
sum(1)(2) // should return 3
0933322888
  • 13
  • 2

1 Answers1

2

Return another function that when called sums the argument of the first and the second like this:

function sum(a) {
  return b => a + b
}
console.log(sum(1)(2))
mdatsev
  • 3,054
  • 13
  • 28