Created
June 16, 2017 23:08
-
-
Save sam-rad/bc0b5aabf6181fdf0f1324534c08a1ee to your computer and use it in GitHub Desktop.
shuffles an array
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
const shuffle = (arr, result=[], idx) => | |
arr.length <= 0 | |
? result | |
: (idx = Math.floor(Math.random() * arr.length), | |
shuffle(arr.filter((_, i) => i !== idx), [ ...result, arr[idx]])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment