Tell us what’s happening:
I feel about 70% confident in what I’m doing below, but I also have a lot of doubt in that confidence and really need someone to shoot a hole in it because I can’t see past it right now. I’ve left my comments related to my logic in my code below.
Your code so far
// the global Array
var s = [23, 65, 98, 5];
Array.prototype.myMap = function(callback){
//I must create a new array because I need something to manipulate besides the global variable per the necessary logic of FP.
var newArray = [];
// As THIS takes on the property of the object in its scope, I use THIS as copy of the callback. I use it to loop through the array and apply the logic of CALLBACK.
for(var i = 0; i < this.length; i++){
newArray.push(this[i]);
//I return newArray with the array callback was called upon within it.
}
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/70.0.3538.110 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype/