Skip to content

Instantly share code, notes, and snippets.

@sam-rad
Created June 16, 2017 23:08
Show Gist options
  • Save sam-rad/bc0b5aabf6181fdf0f1324534c08a1ee to your computer and use it in GitHub Desktop.
Save sam-rad/bc0b5aabf6181fdf0f1324534c08a1ee to your computer and use it in GitHub Desktop.
shuffles an array
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