Functional Programming - Implement map on a Prototype

What’s wrong with my code? For more details, click the challenge link

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

Challenge Information:

Functional Programming - Implement map on a Prototype

When I try to use code with one of the test cases, I’m getting error:

ReferenceError: i is not defined

Please change your code, use ‘B’ instead of ‘i’ because ‘i’ is not defined.


1 Like

Can you say more? We want to know what your question is. What’s not working? What have you tried?

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

1 Like

Hello @bushra.ghames2707 !

I believe the problem is here.

B is used in place of i in the original step, bu then it is i in the lower step. Perhaps, it should have remained B.

Try it and see if it works for you.

Happy coding!

1 Like

Absolutely, I understand the importance of guiding others rather than providing complete solutions. I’ll make sure to offer hints and suggestions to help fellow learners tackle the challenges themselves. Thanks for your feedback.

1 Like