Created
August 30, 2021 17:03
-
-
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.
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
| 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