javascript - Variadic curried sum function -


i need js sum function work this:

sum(1)(2) = 3 sum(1)(2)(3) = 6 sum(1)(2)(3)(4) = 10  etc. 

i heard can't done. heard if adding + in front of sum can done. +sum(1)(2)(3)(4).
any ideas of how this?

not sure if understood want, but

function sum (n) {     var v = function (x) {         return sum (n + x);     };      v.valueof = v.tostring = function () {         return n;     };      return v; }  console.log(+sum(1)(2)(3)(4)); 

jsfiddle


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -