Re: Re: Additional Math functions

2015-10-02 Thread Sebastian Zartner
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

Re: Additional Math functions

2015-10-02 Thread Waldemar Horwat
On 10/01/2015 23:10, Sebastian Zartner wrote: 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

rest parameters

2015-10-02 Thread Michaël Rouges
Hi all, I'm coming to you for a tiny question... excuse me if already replied... Where the rest parameter are only declarable at the end of the arguments list, like this, please? ` void function (a, ...b, c) { // b = [2, 3] }(1, 2, 3, 4); ` Any real reasons? Michaël Rouges -

Re: Re: rest parameters

2015-10-02 Thread Alexander Jones
I guess this is another reason why promisified versions are better: ```js somethingAsync(foo, bar, ...args).then(yourCallback) ``` On 2 October 2015 at 20:31, Michaël Rouges wrote: > For me, the rest parameters must be unique per arguments list but, > logically,

Re: Additional Math functions

2015-10-02 Thread Alexander Jones
I really don't think I'd want a basic `Math.sum(a, b, c)` meaning anything other than `a + b + c`, i.e. `(a + b) + c`. We should all just come to terms with the fact that floating point addition is not associative. Or is there really some simple, O(n) algorithm to do a better (more "careful")

Re: rest parameters

2015-10-02 Thread Tab Atkins Jr.
On Fri, Oct 2, 2015 at 12:09 PM, Steve Fink wrote: > I don't know, but I can speculate. It's not at all obvious how ...args in > the middle should behave: what if you have two rest arguments? Is that > forbidden, or is one greedy? What if one of the trailing parameters has a >

Re: Re: rest parameters

2015-10-02 Thread Michaël Rouges
For me, the rest parameters must be unique per arguments list but, logically, usable following the function requirements... A classical example, the node.js methods, which takes a callback as last argument, preceeded (generally) by one or more arguments, for a same method. Michaël Rouges -

Re: Additional Math functions

2015-10-02 Thread Eli Perelman
In addition, using reduce just to sum array elements forces a function execution for every element. May not be bad for a minimal count of elements, but doing statistical work on larger collections would benefit from having an optimized summation. Eli Perelman On Fri, Oct 2, 2015 at 3:23 PM,

Re: rest parameters

2015-10-02 Thread Steve Fink
On 10/02/2015 11:52 AM, Michaël Rouges wrote: Hi all, I'm coming to you for a tiny question... excuse me if already replied... Where the rest parameter are only declarable at the end of the arguments list, like this, please? ` void function (a, ...b, c) { // b = [2, 3] }(1, 2, 3, 4); ` Any

Re: Additional Math functions

2015-10-02 Thread Waldemar Horwat
On 10/02/2015 13:30, Alexander Jones wrote: I really don't think I'd want a basic `Math.sum(a, b, c)` meaning anything other than `a + b + c`, i.e. `(a + b) + c`. We should all just come to terms with the fact that floating point addition is not associative. Or is there really some simple,

Re: rest parameters

2015-10-02 Thread Michaël Rouges
For the undefined case, it isn't unexistent... ```JavaScript void function () { console.log(arguments.length); // 3 }(1, 2, undefined); ``` Then, I don't see how it may be ambiguous... Michaël Rouges - https://github.com/Lcfvs - @Lcfvs ___

Re: Re: Additional Math functions

2015-10-02 Thread Alexander Jones
Interesting. I still feel that these algorithms should be given their proper names in a math library, because I would feel quite troubled if `Math.sum(a, b, c) !== a + b + c`. Maybe I'm alone in this view, though. What do other languages do? On Friday, 2 October 2015, Waldemar Horwat

Re: rest parameters

2015-10-02 Thread Tab Atkins Jr.
On Fri, Oct 2, 2015 at 3:00 PM, Michaël Rouges wrote: > For the undefined case, it isn't unexistent... > > ```JavaScript > void function () { > console.log(arguments.length); // 3 > }(1, 2, undefined); > ``` > > Then, I don't see how it may be ambiguous... Again,

Re: Additional Math functions

2015-10-02 Thread Waldemar Horwat
On 10/02/2015 16:37, Alexander Jones wrote: Interesting. I still feel that these algorithms should be given their proper names in a math library, because I would feel quite troubled if `Math.sum(a, b, c) !== a + b + c`. Maybe I'm alone in this view, though. What do other languages do? On