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.

Revisions

  1. MoodyBones created this gist Aug 30, 2021.
    10 changes: 10 additions & 0 deletions fisher-yates-shuffle.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    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/