Skip to content

Instantly share code, notes, and snippets.

@nijitaro
Created March 10, 2016 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nijitaro/1d08a1b03bea5d66b08d to your computer and use it in GitHub Desktop.
Save nijitaro/1d08a1b03bea5d66b08d to your computer and use it in GitHub Desktop.
Shuffle Array
const shuffle = arr => {
var i, j, temp;
arr = arr.slice();
i = arr.length;
if (i === 0) {
return arr;
}
while (--i) {
j = Math.floor(Math.random() * (i + 1));
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
return arr;
}
export default shuffle;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment