Skip to content

Instantly share code, notes, and snippets.

@oreillyross
Created March 15, 2016 14:05
Show Gist options
  • Save oreillyross/b0deaa1248e8168b38d3 to your computer and use it in GitHub Desktop.
Save oreillyross/b0deaa1248e8168b38d3 to your computer and use it in GitHub Desktop.
This is the javascript implementation of map
Array.prototype.map = function (fun, thisArg) {
if(typeof fun !== 'function') {
throw new Error("The first argument must be of type function");
}
var arr = [];
thisArg = (thisArg) ? thisArg : this;
thisArg.forEach(function(element) {
arr[arr.length] = fun.call(thisArgs, element);
});
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment