Last active
August 29, 2015 14:23
-
-
Save arterzatij/755e4f28ed8d277b8216 to your computer and use it in GitHub Desktop.
JS utils
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
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; | |
} |
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
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