Merge pull request #88 from darrenscerri/shuffle
This commit is contained in:
8
snippets/shuffle-array.md
Normal file
8
snippets/shuffle-array.md
Normal 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]
|
||||
```
|
||||
Reference in New Issue
Block a user