Tell us what’s happening:
Hi.So i am stuck on this challenge so hard even when i looked the solution on the forum i still could not get it right.Why do we use this
keyword here,can you tell me where exactly does it refers to when we use it in our prototype?Also i am confused with passing the item
and then use this line newArray.push(callback(this[i]));
to fill the newArray.Final question,is it bad that i cant understand this challenge at this point of the curriculum and i had to check the forums solution (and still dont get it )?
Thanks!
Your code so far
// The global variable
var s = [23, 65, 98, 5];
Array.prototype.myMap = function(callback){
var newArray = [];
// Only change code below this line
for(let i=0;i<this.length;i++){
newArray.push(callback(this[i]));
}
// Only change code above this line
return newArray;
};
var 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/84.0.4147.135 Safari/537.36
.
Challenge: Implement map on a Prototype
Link to the challenge: