Functional Programming - Implement map on a Prototype

Tell us what’s happening:
Hello everyone, I have a bit of issue here. I’ve wrote the for loop version but the output of new_s is the same as s which is [23, 65, 98, 5]. not sure why?

the value of newArray.push(this[i]); is [23, 65, 98, 5]

I think this code should work just fine, but it’s not. I’m not sure what I’m missing. please enlight me.
Your code so far

// The global variable
const s = [23, 65, 98, 5];

Array.prototype.myMap = function(callback) {
  const newArray = [];
  // Only change code below this line
  for (let i = 0; i< this.length; i++){
  // Only change code above this line
  return newArray;

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


Your browser information:

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

Challenge: Functional Programming - Implement map on a Prototype

Link to the challenge:

All you are doing is creating a copy of the existing array. That is not what this challenge is expecting you to do. It is supposed to mimic the method which returns a new array whose elements have been modified per the callback function passed to it.

You are not using the callback argument passed to the myMap method.

thankies, with your hint, I change




and it works.
I’m not quite sure why this[i] needs to be inside callback().
my best guess is because callback(this[i]) is called by function(item) of this code:

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

correct me if im wrong.