In this section of the following code;
newArray.push(callback(this[i], i, this))
can you explain the code?
Why do we write : newArray.push(callback(this[i], i, this))
Array.prototype.myMap = function(callback) {
const newArray = [];
// Only change code below this line
fo (let i = 0; i < this.length; i++) {
newArray.push(callback(this[i], i, this))
}
// Only change code above this line
return newArray;
};
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
Challenge: Functional Programming - Implement map on a Prototype
Link to the challenge: