Merge pull request #88 from darrenscerri/shuffle

This commit is contained in:
Angelos Chalaris
2017-12-14 11:10:47 +02:00
parent 3b0fa08fdd
commit f8d55631c6
4 changed files with 11 additions and 24 deletions

View File

@ -0,0 +1,8 @@
### Shuffle array
Use `Array.sort()` to reorder elements, using `Math.random()` in the comparator.
```js
const shuffle = arr => arr.sort(() => Math.random() - 0.5);
// shuffle([1,2,3]) -> [2,3,1]
```