Hi - a few questions about functions.
-
why is this problem using myMap not map? I don’t understand it’s significance.
-
which solution type should I be focused on? Initially when I was looking at arrows and some other es6 topics, I was trying to learn algorithms and so I didn’t really focus a lot on each concept (also there wasn’t enough practice with them). Now I’m seeing that varies problems focus on es6. For example one solution to this is
this.forEach(a => newArray.push(callback(a)));
. I thought to myself ideally I’d learn all, but of course that’s not easy when I’m starting out so I thought it’d be worth asking. -
I may have asked this before but is there a better alternative than mozilla docs? As a beginner I feel like I’m reading a textbook as there are so many ways each thing could be used. I just want to learn the part about my specific issue so I can learn based on this course. For example, a place with a topic navigation would be nice vs reading the entire page and trying to determine which definition is appropriate.
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 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36
.
Challenge: Implement map on a Prototype
Link to the challenge: