Files
30-seconds-of-code/snippets/shuffle-array.md
Stefan Feješ b848906fe5 fix naming
2017-12-17 15:41:31 +01:00

207 B

Shuffle array

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

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