Skip to content

Instantly share code, notes, and snippets.

@rootux
Last active December 11, 2016 12:46
Show Gist options
  • Save rootux/29ea80b88b12c43f4b897f38f5c637cd to your computer and use it in GitHub Desktop.
Save rootux/29ea80b88b12c43f4b897f38f5c637cd to your computer and use it in GitHub Desktop.
Midburnerot omg sale shuffle from array of emails
/*
* Based on Fisher-Yates (Aka Knuth) shuffle
* https://github.com/Daplie/knuth-shuffle
*/
Array.prototype.shuffle = function() {
let currentIndex = this.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = this[currentIndex];
this[currentIndex] = this[randomIndex];
this[randomIndex] = temporaryValue;
}
return this;
};
let omgPeople = ["[email protected]","[email protected]", "[email protected]"];
omgPeople.shuffle();
let winners = omgPeople.slice(0,150);
console.log(winners);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment