Array.prototype.myMap = function(callback) {
const newArray = ;
// Only change code below this line
for (let i = 0; i < this.length; i++){
newArray.push(callback(this[i], i, this));
}
// Only change code above this line
return newArray;
};
console.log([23, 65, 98, 5, 13].myMap(item => item * 2));
Why does the solution call for a push of callback(this[i] - with an additional - “i, this”) into the newArray variable? I am uncertain of why callback(this[i] is followed by “i, this”.
The previous lesson indicated that “The first argument is the current element being processed. The second is the index of that element and the third is the array upon which the map method was called.” However; the following problem deals with a for loop and the map method is not used. What would the 3 arguments in the callback function be now?