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
0

1 Answer 1

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))

Sign up to request clarification or add additional context in comments.

1 Comment

it works only for exactly two values.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.