Gbadebo Bello (2018-11-19T00:34:27.000Z)
Yh, i felt the same way about the rest also but thought it would be nice to
atleast get feedback b concluding.

---------- Forwarded message ---------
From: Gbadebo Bello <gbahdeybohbello at gmail.com>
Date: Mon, Nov 19, 2018, 01:27
Subject: Re: Numeric Array prototypes (Isiah Meadows)
To: Isiah Meadows <isiahmeadows at gmail.com>


Yh, i felt the same way about the rest also but thought it would be nice to
atleast get feedback before concluding.

On Wed, Nov 21, 2018, 06:08 Isiah Meadows <isiahmeadows at gmail.com> wrote:

> Not sure these belong in the standard library itself. I could see max and
> min being there (these are very broadly useful), but the others, not so
> much. I'd also like both max and min accept an optional comparison callback
> of `(a, b) => a < b`. But the rest seem too narrowly useful IMHO.
> On Tue, Nov 20, 2018 at 21:38 Gbadebo Bello <gbahdeybohbello at gmail.com>
> wrote:
>
>> The array object has no method for finding the minimum value of an array
>> of numbers and the Math.min() method doesn't work on Arrays right out of
>> the box. I'll have similar issues if i wanted to return the maximum number,
>> the mean, mode,  median or standard deviations in any array of numbers.
>>
>> This is a bit tasky and can be done in just a line of code if there where
>> Array.prototype.{method}() for it.
>>
>> My proposal is, Arrays should have the following prototypes
>>
>>    1. Array.prorotype.min()
>>    2.  Array.prorotype.max()
>>    3. Array.prorotype.mean()
>>    4. Array.prorotype.median()
>>    5. Array.prorotype.mode()
>>    6. Array.prototype.stdev()
>>
>> The mean, median and mode would be very useful when visuali
>> Here's is a polyfill of what i'll love to propose.
>>
>> //Array.prototype.min()
>> Array.prototype.min = function(){
>> let arrayVal = this;
>> let checkNonNumbers = this.some(element => {
>> if(typeof(element) !== typeof(Math.random())){
>> throw new Error("This Array.prorotype.min() takes only array of numbers
>> as arguments");
>> }
>> else{
>> return true;
>> }
>> });
>> function findMin(validated){
>> if(validated == true){
>> return Math.min.apply( Math, arrayVal );
>> }
>> }
>> return findMin(checkNonNumbers);
>> }
>>
>> Similarly, Array.prototype.max() can be implemented as above.
>>
>>
>>
>> //Array.prototype.median()
>> Array.prototype.median = function(){
>> let values = this;
>> function median(values){
>> values.sort(function(a,b){
>> return a-b;
>> });
>> if(values.length ===0) return 0
>> var half = Math.floor(values.length / 2);
>> if (values.length % 2)
>> return values[half];
>> else
>> return (values[half - 1] + values[half]) / 2.0;
>> }
>> return median(numbers)
>> }
>> _______________________________________________
>> 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/20181119/4feb70b5/attachment-0001.html>
gbahdeybohbello at gmail.com (2018-11-22T00:28:28.281Z)