Functional Programming - Implement map on a Prototype

I have no idea what the problem is here. I know I’m still in the beginner stages of things but geesh, thought I’d be making some progress by now.

Any help is much appreciated!

Array.prototype.myMap = function(callback) {
  const newArray = [];
  // Only change code below this line
this.forEach(item => newArray.push(callback(item)));
  // 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/605.1.15 (KHTML, like Gecko) Version/16.5.1 Safari/605.1.15

Challenge: Functional Programming - Implement map on a Prototype

Link to the challenge:

Trying the failing test case will give some error in console. Check:

[1, 1, 2, 5, 2].myMap((element, index, array) => array[index + 1] || array[0])

Take also a closer look at the test case itself. Previous ones are passing because callback function is having just a single parameter. However map method can take callback with more parameters.

This is what threw me off. It took about a day to find this solution.
The third test case requires three parameters.

So is it correct to say that in the first two cases, the 2nd and 3rd parameters are ignored?

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