Files
30-seconds-of-code/snippets/randomize-order-of-array.md
2017-12-12 07:11:37 -05:00

207 B

Randomize order of array

Use sort() to reorder elements, utilizing Math.random() to randomize the sorting.

const randomizeOrder = arr => arr.sort( (a,b) => Math.random() >= 0.5 ? -1 : 1)