Tell us what’s happening:
Array.prototype.myMap = function(callback) {
const newArray = ;
// Only change code below this line
newArray = this.slice(0);
const newArray2 = ;
for(let i = 0; i < newArray.length; i++){
newArray2.push(callback(newArray[i], i, newArray));
}
console.log(newArray2.length)
// Only change code above this line
return newArray2;
};
why is my code not working? Also, how am I supposed to know how the callback function works and what arguments it needs?
Your code so far
Array.prototype.myMap = function(callback) {
const newArray = [];
// Only change code below this line
newArray = this.slice(0);
const newArray2 = [];
for(let i = 0; i < newArray.length; i++){
newArray2.push(callback(newArray[i], i, newArray));
}
console.log(newArray2.length)
// Only change code above this line
return newArray2;
};
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Challenge Information:
Functional Programming - Implement map on a Prototype