1

I'm trying to solve some javascript puzzle. I have some function (for example a function which calculates summa). But there is a weird calling of that function. example:

sum(5)

or sum(5,6) - should be 11

or sum(5)(6) - should be 11

or sum(1)(2)(3) - should be 6

Have never seen such function calling sum(1)(2)(3)(4).... Can you please explain or maybe put into documentation where this stuff is explained?

Thanks a lot.

vitasya
  • 355
  • 5
  • 17
  • 1
    If the `sum` function returns a function, that function can also be invoked. – David Jan 04 '22 at 16:57
  • 3
    Does the **accepted answer** answer your question? [What is 'Currying'?](https://stackoverflow.com/questions/36314/what-is-currying) – Randy Casburn Jan 04 '22 at 16:59
  • I've tried return function inside function, but it works only with sum(1) and sum(2,3), but not with sum(2)(3) and more :( – vitasya Jan 04 '22 at 17:00

1 Answers1

0

If the sum function returns a value that it can reuse, you can chain the numbers on and on.

If you can share the function it can be easier to explain

Deniz Karadağ
  • 751
  • 3
  • 8