Additional Math functions

Rick Waldron waldron.rick at gmail.com
Mon Oct 5 19:09:58 UTC 2015


On Mon, Oct 5, 2015 at 2:58 PM Marius Gundersen <gundersen at gmail.com> wrote:

> Wouldn't it make sense to wait for the bind syntax [1] before introducing
> new methods that work on arrays?
>

The functions don't accept arrays or operate on arrays—they accept any
number of arguments (eg. Math.hypot, Math.min, Math.max) and operate on
those arguments as a list.


> That way it could be added to a standard or non-standard module without
> altering either the Math object or the Array/Iterator prototype. Something
> like this:
>
> ```
> import {sum, mean} from "iterator-math";
>
> [1,2,3,4]::sum(); //10
> [1,2,3,4]::mean(); //2.5
> [{a:1}, {a:2}, {a:3}, {a:4}].map(x => x.a)::sum(); //10
> ```
>

These aren't particularly compelling considering the following can written
without waiting for a bind operator:

  let { sum, mean } = Math;

  sum(...[1, 2, 3, 4]) // 10
  mean(...[1, 2, 3, 4]) // 2.5
  sum(...[{a:1}, {a:2}, {a:3}, {a:4}].map(x => x.a)) //10

(And remain consistent with existing Math.*(...) operations)

Rick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151005/c406ccd7/attachment.html>


More information about the es-discuss mailing list