Skip to content

Instantly share code, notes, and snippets.

@MoodyBones
Created August 30, 2021 17:03
Show Gist options
  • Select an option

  • Save MoodyBones/bf6a2f4b0e53967bbf51ad0a0679ae6f to your computer and use it in GitHub Desktop.

Select an option

Save MoodyBones/bf6a2f4b0e53967bbf51ad0a0679ae6f to your computer and use it in GitHub Desktop.
lodash shuffle is fisher-yates shuffle under the hood. I learnt this from Sarah Drasner.
function shuffle(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]]
}
return array
}
// Snippet by Sarah Drasner
// More shuffling ---> https://bost.ocks.org/mike/shuffle/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment