Sebastian Zartner sebastianzartner at gmail.com
Fri Oct 2 06:10:59 UTC 2015

```While Math.sum() and Math.mean() currently don't exist, they can easily be
polyfilled:
See
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce#Sum_all_the_values_of_an_array
for summarizing the values of an array and the following code for building
the average of the array values:

let arr = [0, 1, 2, 3];
let total = arr.reduce(function(a, b) {
return a + b;
});
let mean = total / arr.length;

Calculating the variance and standard deviation would require a bit more
code, though are also easy to polyfill.
Non-the-less I can see the need for having standard functions for this.

Sebastian

On 2 October 2015 at 00:55, Eli Perelman <eli at eliperelman.com> wrote:

> In case it didn't come across, this is the thread I'm reviving:
>
> https://mail.mozilla.org/pipermail/es-discuss/2015-April/042732.html
>
> Eli Perelman
> Mozilla
>
> On Thu, Oct 1, 2015 at 5:51 PM, Eli Perelman <eli at eliperelman.com> wrote:
>
>> Reviving this thread, doing any type of simple statistics is more verbose
>> than it probably needs to be as calculating sums, averages, etc. makes most
>> resort to Array reduction. I understand the need for methods such as
>> `Math.hypot(...values)`, but for ECMAScript to evolve to be useful in
>> statistics programming without needing to resort to R would definitely also
>> be a nice-to-have. I'm sure there are many statistical functions you
>> *could* add, but at a bare minimum, it would be useful:
>>
>> Math.sum(...values) or Math.summation(...values)
>> Math.mean(...values) // Spelling out mean here is succinct while still
>> Math.variance(...values)
>> Math.stddev(...values)
>>
>> Obviously some of these can be computed from the results of others, but I
>> think the convenience and intent of the methods, not to mention their wide
>> usefulness outweigh the concern of Math bloat. Thoughts?
>>
>> P.S. Definitely not against even more core stats methods, but have to
>> start somewhere. :)
>>
>> Eli Perelman
>> Mozilla
>>
>
>
> _______________________________________________
> 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/20151002/ec472304/attachment-0001.html>
```