Skip to content

Instantly share code, notes, and snippets.

@abarrak
Created July 15, 2017 12:14
Show Gist options
  • Select an option

  • Save abarrak/19a4e724b7f0a5ad07fd4c1e37098148 to your computer and use it in GitHub Desktop.

Select an option

Save abarrak/19a4e724b7f0a5ad07fd4c1e37098148 to your computer and use it in GitHub Desktop.
Extends Array in vanilla javascript
Array.prototype.sample = function() {
return this[Math.floor(Math.random() * this.length)]
};
Array.prototype.remove = function(element) {
var index = this.indexOf(element);
if (index > -1) {
this.splice(index, 1);
}
return this;
};
function getRand(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment