Skip to content

Latest commit

 

History

History
10 lines (7 loc) · 245 Bytes

shuffle.md

File metadata and controls

10 lines (7 loc) · 245 Bytes

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]