Skip to content

Instantly share code, notes, and snippets.

Avatar

Anthony Woodard anthonywoodard

View GitHub Profile
@anthonywoodard
anthonywoodard / JavaScriptArrayMap
Created Dec 14, 2012
JavaScript Array Map Function
View JavaScriptArrayMap
Array.prototype.map = function (fn) {
var l = this.length;
var a = [];
for (var i = 0; i < l; i++) {
a.push(fn(this[i]));
}
return a;
};
@anthonywoodard
anthonywoodard / JavaScriptArrayReduce
Created Dec 14, 2012
JavaScript Array Reduce Function
View JavaScriptArrayReduce
Array.prototype.reduce = function (fn, init) {
var s = init;
var l = this.length;
for (var i = 0; i < l; i++) {
s = fn(s, this[i]);
}
return s;
};
You can’t perform that action at this time.