Tell us what’s happening:
Hi campers, I’m confused about the use of this
in this exercise as well as the 3 args in the callback function. I have peeked quickly at the solution as I wasn’t getting anywhere, and noticed that that the call back function takes 3 arguments, which I’ve not seen before. Looking at an previously answered question, it says that is normal, but I haven’t seen its implementation used before and was wondering if someone might be able to explain what is happening, especially when used with this
Your code so far
Array.prototype.myMap = function(callback) {
const newArray = [];
// Only change code below this line
//Why just this, why not this.Array?
for (let i = 0; i < this.Array.length; i++){
/*I know there should be 3 args in here, but I don't know how or why they are implemented as they are*/
newArray.push(callback(this.Array[i]))
console.log(newArray)
}
// Only change code above this line
return newArray;
};
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Challenge Information:
Functional Programming - Implement map on a Prototype