Proposal: Array.prototype.shuffle (Fisher-Yates)

Tab Atkins Jr. jackalmage at gmail.com
Sun Apr 29 18:06:24 UTC 2018


On Sun, Apr 29, 2018 at 10:01 AM, Isiah Meadows <isiahmeadows at gmail.com> wrote:
> I think this would be better suited for a library function rather than
> a language feature. I could see this also being useful also for
> randomized displays, but that's about it. And I'm not sure what an
> engine could provide here that a library couldn't - you can't really
> get much faster than what's in the language (minus bounds checking,
> but the likely frequent cache misses will eclipse that greatly), and
> it's not unlocking any real new possibilities.

Yes, this is very easily doable in userland, and a built-in will have
little if any speed benefit.

The point, tho, is that this is (a) a relatively common operation, and
(b) very, very easy to do *wrong*, as demonstrated by the SO link.
Thus it's a reasonable candidate for inclusion as a built-in anyway,
to avoid the footgun of trying to do it yourself and screwing it up.

~TJ


More information about the es-discuss mailing list