Functional Programming - Implement map on a Prototype

Tell us what’s happening:
Hi! I have seen the solution and I’m really confused. The callback function doesn’t seem to be a built-in function of Javascript. I googled and didn’t find such a function. And I don’t see it defined anywhere in the exsiting code. I don’t understand why the solution let it have 3 parameters and what it does inside the function.

Your code so far

Array.prototype.myMap = function(callback) {
  const newArray = [];
  // Only change code below this line
  for(let i = 0; i < this.length; i++){
    newArray.push(this[i]);
  }
  // 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/114.0.0.0 Safari/537.36

Challenge: Functional Programming - Implement map on a Prototype

Link to the challenge:

I’d review the previous challenge. The callback is a function passed to the map method by the user.

1 Like

Hi, Sophie.
To add some feedback, a callback function is not a function, it’s a function type, it could be any function, you define it yourself when you type it as an argument that you give to another function.

In the first test, item => item * 2 is the callback function given to myMap.

Those three parameters are called: a fallback function signature.

2 Likes

Thank you very much! I have understand what my problem is.

1 Like

Thank you very much! I will check the previous step.

1 Like

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