Created
March 15, 2016 14:05
-
-
Save oreillyross/b0deaa1248e8168b38d3 to your computer and use it in GitHub Desktop.
This is the javascript implementation of map
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.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