Implement map on a Prototype!?

So Im not understanding, we are trying to define a prototype myMap, that modifies its argument, even if the argument is a function, as in s.myMap(function(item)). Are we just pushing the elements onto the new array?

Your code so far


// the global Array
var s = [23, 65, 98, 5];

Array.prototype.myMap = function(callback){
  var newArray = [];
  // Add your code below this line

  // Add your code above this line
  return newArray;

};

var new_s = s.myMap(function(item){
  return item * 2;
});

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype

You are trying to recreate what Array.prototype.map does. See the previous lesson on how map works.

I have written the following code, but I dont know how to implement the function call of returning x*2 within the prototype definition

// the global Array
var s = [23, 65, 98, 5];

Array.prototype.myMap = function(callback){
  var newArray = [];
  // Add your code below this line
  for (let i=0;i<this.length;i++)
  {
    newArray.push(this[i]);
    console.log(this[i]);
  }

  // Add your code above this line
  return newArray;

};

var new_s = s.myMap(function(item){
  return item * 2;
});

Well, callback, which is the method parameter, is a function, but you are not using it anywhere.