Tell us what’s happening:
Can someone maybe clarify this challenge? If I understand correctly, I am trying to basically create the map() function by doing a traditional forloop. However when I console.log the condition in the for loop, I have no output. What am I doing wrong?
My thought process was to iterate through whatever is passed through the callback argument and push the result into newArray. But, I must be incorrect?
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 < callback.length; i++){
if(callback > 0){
console.log(callback);
newArray.push(callback[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.125 Safari/537.36
.
Challenge: Implement map on a Prototype
Link to the challenge: