Files
30-seconds-of-code/snippets/shuffle.md
Angelos Chalaris 5c2eeb3bcc Updated examples
2017-12-27 16:06:16 +02:00

253 B

shuffle

Randomizes the order of the values of an array.

Use Array.sort() to reorder elements, using Math.random() in the comparator.

const shuffle = arr => arr.sort(() => Math.random() - 0.5);
shuffle([1,2,3]) // [2,3,1]