Functional Programming - Implement map on a Prototype

Tell us what’s happening:

Just so I understand what is going on, on the first line when we pass “callback” as an argument, the “callback” is a function itself correct? Also, on the next line (line 5) containing “callback(element, index, originalArr)” I do not understand the use of callback, like what is the logic behind that? What is the callback function actually doing?

Your code so far

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

Challenge Information:

Functional Programming - Implement map on a Prototype

It depends on what callback function is used, but the purpose of the callback is to create new array elements out of the old elements here.

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