Skip to content

Instantly share code, notes, and snippets.

@arterzatij
Last active August 29, 2015 14:23
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 arterzatij/755e4f28ed8d277b8216 to your computer and use it in GitHub Desktop.
Save arterzatij/755e4f28ed8d277b8216 to your computer and use it in GitHub Desktop.
JS utils
Array.prototype.contains = function(obj) {
var i = this.length;
while (i--) {
if (this[i] === obj) {
return true;
}
}
return false;
}
Array.prototype.max = function() {
return Math.max.apply(null, this);
};
Array.prototype.min = function() {
return Math.min.apply(null, this);
};
Array.prototype.remove = function() {
var what, a = arguments, L = a.length, ax;
while ( L && this.length ) {
what = a[--L];
while( ( ax = this.indexOf( what ) )!= -1 ){
this.splice(ax, 1);
}
}
return this;
}
Object.prototype.isEmpty = function() {
return Object.keys(this).length == 0;
}
Object.prototype.hasProp = function( propName ) {
return this.isEmpty() ? false : Object.keys(this).contains(propName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment