Skip to content

Instantly share code, notes, and snippets.

@MarcusHurney
Created February 13, 2017 00:28
Show Gist options
  • Save MarcusHurney/8837f155e6ac14416334195cefd55e9a to your computer and use it in GitHub Desktop.
Save MarcusHurney/8837f155e6ac14416334195cefd55e9a to your computer and use it in GitHub Desktop.
Array.prototype.createMap = Array.prototype.createMap || function(callback) {
var newArray = [];
for (var i = 0; i < this.length; i++) {
var result = callback(this[i], i);
newArray.push(result);
}
return newArray;
}
var start = [1, 2, 3];
var transformedArray = start.createMap(function(value, index) {
return value + 1;
});
console.log(transformedArray);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment