Created
September 14, 2010 10:36
-
-
Save jarrettmeyer/578843 to your computer and use it in GitHub Desktop.
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
// Because I am an idiot and keep on using 'append', instead of 'push'. | |
Array.prototype.append = function (item) { | |
this.push(item); | |
return this; | |
}; | |
// Returns true if the given item is contained in the array. | |
Array.prototype.contains = function (item) { | |
for (var i = 0; i < this.length; i++) { | |
if (this[i] == item) return true; | |
} | |
return false; | |
}; | |
// Perform the given action on each element of the array. | |
Array.prototype.each = function (action) { | |
for (var i = 0; i < this.length; i++) { | |
action(this[i]); | |
} | |
}; | |
// Remove all occurrences of the given item from an array. | |
Array.prototype.remove = function (item) { | |
var i = 0; | |
while (i < this.length) { | |
if (this[i] == item) { | |
this.splice(i, 1); | |
} else { | |
i++; | |
} | |
} | |
return this; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment