Files
30-seconds-of-code/snippets/shuffle.md
2017-12-25 14:49:52 +01:00

14 lines
253 B
Markdown

### shuffle
Randomizes the order of the values of an array.
Use `Array.sort()` to reorder elements, using `Math.random()` in the comparator.
```js
const shuffle = arr => arr.sort(() => Math.random() - 0.5);
```
```js
shuffle([1,2,3]) -> [2,3,1]
```