Implement map on a Prototype - Question

Please see code below.

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”.

What did the previous lesson say the format of the callback function was?

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?


You are supposed to be completely replicating the map method, so all three arguments must do the exact same thing

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.