Functional Programming - Implement map on a Prototype

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:

Can you explain what part of the code you do not understand?

Keep in mind, you have a typo on the following line:

  fo (let i = 0; i < this.length; i++) {
1 Like

ooovvVV :sweat_smile: correct!
fo => for … should have been
thank you!

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