DEV Community

Discussion on: Mastering Javascript One-Liners to Look Like a Pro

Collapse
 
oculus42 profile image
Samuel Rouse • Edited

There are a lot of great one-liners in here that can be very useful, but we may need to be more careful with array shuffling. For some purposes a simple random shuffle will suffice, but most shuffles have bias in them, and the amount of bias can depend on the JavaScript engine.

The Fisher-Yates shuffle is reliable and unbiased.

For a good visualization of differences, take a look at Mike Bostock's page Will It Shuffle? and try it in different browsers to see the variation.

Collapse
 
benajaero profile image
ben ajaero

That's true I considered including the bias, however I thought it might confuse people more.
The Fisher-Yates algorithm is great!