Implement map on a Prototype | Functional Programming

I am encountering a strange problem. I don’t understand what the the exercise is asking me to do. Should I just look at the answer?

Link to the module-


You need to create a new prototype function of Array that acts like this:

But we can’t use the map function.

The challenge wants you to add a custom function to the Prototype with the same functionality that does
i.e. loop through each elements and and apply the provided callback function and push to new array , and return the array with newly calculated elements.

All too confusing. I had to look at the solution because I was lost on ideas how to approach the problem. In the first solution why do we have this.length? shouldn’t it be callback.length?
Please guide

Try logging this and see what’s the value of it.

when I try to log this value is undefined. console.log(this).

Log it inside the function, and try to not look at the solutions, you are hindering your learning and progress


this in Javascript
w3schools has a nice introduction about this keyword in JS. It’s a good starting point for understanding this .

1 Like

Thanks!! @saurabhv749 :star2: :star2:

You are right. But sometimes I don’t know what else to do :frowning: I will try more. Thank you for getting back :star2: :star2:

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