Feature request: Array.prototype.random

William White w.white9 at icloud.com
Thu Jun 15 22:20:08 UTC 2017


And prng.pick(str), prng.pick(set) etc.?

> On 15 Jun 2017, at 22:34, Michał Wadas <michalwadas at gmail.com> wrote:
> 
> I believe it's too specialized to be a part of Array interface. 
> 
> Though, I think JS should have better support for randomness, so we could do:
> 
> prng.pick(arr);
> prng.sample(arr, 5);
> prng.sampleWithoutRepetitions(arr, 4);
> 
> On 15 Jun 2017 20:42, "Will White" <w.white9 at icloud.com> wrote:
> Dear es-discuss,
> 
> I would like to propose Array.prototype.random, which would return a random array element the same way `array[Math.floor(Math.random() * array.length)]` does, because every time I want a random array element, I have to remember how to do it. Do you think this is a useful addition to the language?
> 
> Will White
> _______________________________________________
> 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/20170615/98c547f3/attachment.html>


More information about the es-discuss mailing list