Last active
December 11, 2016 12:46
-
-
Save rootux/29ea80b88b12c43f4b897f38f5c637cd to your computer and use it in GitHub Desktop.
Midburnerot omg sale shuffle from array of emails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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