Skip to content

Instantly share code, notes, and snippets.

@rootux
Last active December 11, 2016 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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 = ["person1@gmail.com","person2@gmail.com", "person3@gmail.com"];
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