I am looking at trying to implement the map function myself.
So far my code looks like this:
Array.prototype.mapz = function (callback) {
let arr = []
for (let i = 0; i < array.length; i++) {
arr.push(callback(array[i]));
}
return arr;
};
function double(arg) {
return arg * 2
};
const x = [1, 2, 3].mapz(double);
console.log(x); // This should be [2, 3, 6];
I am wondering how I can get access to the array I am mapping over in my mapz method?