-
-
Save secantsquared/87c790e64167f31b0c38f6e99f96f0dd to your computer and use it in GitHub Desktop.
Shuffle array element ES2015, ES6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // original gist | |
| const shuffleArray = arr => arr.sort(() => Math.random() - 0.5); | |
| // fully random by @BetonMAN | |
| const shuffleArray = arr => ( | |
| arr | |
| .map(a => [Math.random(), a]) | |
| .sort((a, b) => a[0] - b[0]) | |
| .map(a => a[1]); | |
| ); | |
| shuffleArray(([1, 2, 3]) //[3, 1, 2]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment