Skip to content

Instantly share code, notes, and snippets.

@ganey
Created December 11, 2014 14:36
Show Gist options
  • Save ganey/ef0ee94bc555ca9d61fd to your computer and use it in GitHub Desktop.
Save ganey/ef0ee94bc555ca9d61fd to your computer and use it in GitHub Desktop.
Fisher Yates JS Secret Santa
var a = "joe tom dave mike mark sue lauren".split(" "), b = 0, c = a, d, e, f, g = c.length;
for (d = 0;d < g;d++) {
f = ~~(Math.random() * (d + 1)), e = c[d], c[d] = c[f], c[f] = e;
}
for (a = c;b < a.length;) {
console.log(a[b] + " => " + (b + 1 < a.length ? a[b + 1] : a[0])), b++;
}
;
Copy link

ghost commented Dec 12, 2014

Concise!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment