I was glad to grasp use of this for this challenge.
However, I get ‘‘newArray is not defined’’ when executing the below code
This problem is resolved if one cuts and pastes newArray from outside where it is defined in the function as below and define it as a global variable like s.
Small technicality as I ‘‘think’’ I got the main learning of this challenge but want to ensure consistency.
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
for (var i=0 ; i<this.length; i++) {
newArray.push(callback(this[i]));
};
// Add your code above this line
return newArray;
};
var new_s = s.myMap(function(item){
return item * 2;
});
console.log(newArray);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype/