# Additional Math functions

Tue Oct 6 15:13:26 UTC 2015

```+1 for operating on arrays, though. That's too common of a case for most of
this. Either that or a common helper function:

```js
function apply(xs, f) {
return f(...xs)
}

[1, 2, 3, 4]->apply(Math.sum)
```

(There is talk of changing the syntax and splitting up the proposal in
https://github.com/zenparsing/es-function-bind/issues/26. It could use a
signal boost about now.)

On Mon, Oct 5, 2015, 15:10 Rick Waldron <waldron.rick at gmail.com> wrote:

> 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  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
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151006/5b1787ef/attachment.html>
```