Created
November 11, 2009 03:55
-
-
Save dansimpson/231548 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.each = function(fn, scope) { | |
var count = 0; | |
while(count < this.length) { | |
fn.call(scope || window, this[count], count) | |
count++; | |
} | |
}; | |
Array.prototype.search = function(fn) { | |
var result = []; | |
var count = 0; | |
while(count < this.length) { | |
if(fn(this[count])) { | |
result.push(this[count]); | |
} | |
count++; | |
} | |
return result; | |
}; | |
Array.prototype.collect = function(fn, scope) { | |
var result = []; | |
var count = 0; | |
while(count < this.length) { | |
result.push(fn.call(scope || window, this[count])); | |
count++; | |
} | |
return result; | |
}; | |
Array.prototype.aggregate = function(fn) { | |
var result = 0; | |
var count = 0; | |
while(count < this.length) { | |
result += fn(this[count]); | |
count++; | |
} | |
return result; | |
}; | |
Array.prototype.contains = function(item) { | |
return this.indexOf(item) != -1; | |
}; | |
Array.prototype.first = function() { | |
return this[0] | |
}; | |
Array.prototype.last = function() { | |
return this[this.length - 1] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment