Functional Programming - Implement map on a Prototype

Tell us what’s happening:
[1, 1, 2, 5, 2].myMap((element, index, array) => array[index + 1] || array[0]) should return [1, 2, 5, 2, 1]

Your code so far

Array.prototype.myMap = function(callback) {
  const newArray = [];
  // Only change code below this line
    this.forEach(a => newArray.push(callback(a)));
  // 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/116.0.0.0 Safari/537.36

Challenge: Functional Programming - Implement map on a Prototype

Link to the challenge:

Can this code handle the callback here:

How many arguments are there in the callback in the test?

thank you very much sir

1 Like