"Implement a Map prototype" with forEach?

"Implement a Map prototype" with forEach?
0

#21

If you read the map documentation I linked earlier, you will notice the function accepts 3 arguments which represent (in order) the current element being iterated over, the index of the current element being iterated over, and the original array being iterated over. For this challenge, you only need to think about the first argument. You should also notice that the function being passed in this challenge takes one argument (num). You need to figure out how to use the callback function so that the argument’s value is the element being iterated over in your for loop.


#22

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

};

after going through some discussion in the past of the forum, I seem to have better understand now. I will study further about the link you provided earlier =]

thanks a lot for your help =]