Tell us what’s happening:
Hello everyone, i found the solution on internet, but in fact i can’t understand what is happening with this this.forEach(item => newArray.push(callback(item)));
I can’t understand why using this in this case and how we can access item, if in the parameters we only have callback and not callback(item)
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
this.forEach(item => newArray.push(callback(item)));
// Add your code above this line
return newArray;
};
var new_s = s.myMap(function(item){
return item * 2;
});
Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, if you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.