Skip to content

Instantly share code, notes, and snippets.

@jonrandy
Last active July 16, 2024 08:29
Show Gist options
  • Save jonrandy/d97d8fd17849c2069d9a2447b8e99c9b to your computer and use it in GitHub Desktop.
Save jonrandy/d97d8fd17849c2069d9a2447b8e99c9b to your computer and use it in GitHub Desktop.

Revisions

  1. jonrandy revised this gist Jan 27, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion fisher.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ function shuffle(array) {
    let a = [...array], m = a.length, i
    while (m) {
    // Pick a remaining element
    i = ~~(Math.random() * m--)
    i = ~~(Math.random() * m--);
    // Swap it with the current element
    [a[m], a[i]] = [a[i], a[m]]
    }
  2. jonrandy revised this gist Jan 25, 2023. 1 changed file with 6 additions and 11 deletions.
    17 changes: 6 additions & 11 deletions fisher.js
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,10 @@
    function shuffle(array) {
    let a = [...array], m = a.length, i, ;

    let a = [...array], m = a.length, i
    while (m) {

    // Pick a remaining element…
    i = ~~(Math.random() * m--);

    // And swap it with the current element.
    [a[m], a[i]] = [a[i], a[m]]

    // Pick a remaining element
    i = ~~(Math.random() * m--)
    // Swap it with the current element
    [a[m], a[i]] = [a[i], a[m]]
    }

    return a;
    return a
    }
  3. jonrandy created this gist Jan 3, 2023.
    15 changes: 15 additions & 0 deletions fisher.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    function shuffle(array) {
    let a = [...array], m = a.length, i, ;

    while (m) {

    // Pick a remaining element…
    i = ~~(Math.random() * m--);

    // And swap it with the current element.
    [a[m], a[i]] = [a[i], a[m]]

    }

    return a;
    }