Skip to content

Instantly share code, notes, and snippets.

@axelinternet
Created November 6, 2018 13:40
Show Gist options
  • Save axelinternet/1f7cfe6d16d7017d1e4e70ab25b7e7c2 to your computer and use it in GitHub Desktop.
Save axelinternet/1f7cfe6d16d7017d1e4e70ab25b7e7c2 to your computer and use it in GitHub Desktop.
Durstenfeld shuffle
const shuffleArray = array => {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]]; // eslint-disable-line no-param-reassign
}
return array
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment