Skip to content

Instantly share code, notes, and snippets.

@prettymuchbryce
Created February 4, 2014 00:13
Show Gist options
  • Save prettymuchbryce/8795141 to your computer and use it in GitHub Desktop.
Save prettymuchbryce/8795141 to your computer and use it in GitHub Desktop.
Ruby-style random element method.
Array.prototype.sample = function() {
return this[Math.floor(Math.random() * this.length)];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment