Created
December 16, 2014 05:06
-
-
Save rike422/6d567a6c2c4978257d8b to your computer and use it in GitHub Desktop.
Array.sample
This file contains hidden or 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
Array.prototype.sample = function(loop) { | |
var result = [], loop = loop || 1; | |
for(var i = 0; i < loop; i++) { | |
result.push(this[Math.floor(Math.random() * this.length)]); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment