Add basic arithmetic to Math

Angus Croll anguscroll at gmail.com
Sun Jun 10 11:48:06 PDT 2012


Rationale:

Some functional JavaScript
idioms<https://twitter.com/skilldrick/status/211868188806352896>are
hamstrung by the lack of native basic arithmetic functions.
Would be handy/elegant/instructive to be able to write

arr.reduce(Math.add);

Moreover having functional versions of arithmetic operators would improve
the currying/partial/composition experience.

Caveats:

1. Arrow functions work pretty well too:
arr.reduce((a,b)=>a+b);

2. If add and multiply accepted multiple args, reduce would not be
necessary for these cases:
Math.add.apply(null, arr);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120610/e8cbebed/attachment.html>


More information about the es-discuss mailing list