Tell us what’s happening:
Could someone explain to me why does the function got an argument named callback? I went through a few challenges and I just don’t seem to understand it. Is it a keyword, or what?
What does a function(callback) do? How does JS know?
Sorry, I don’t even know how to ask. I’m just hoping someone would understand what I’m trying to ask.
If you could point me to a website where it is explained in first grade level , I’d be extremely grateful.
Thank you in advance!!
Your code so far
// The global variable
var s = [23, 65, 98, 5];
Array.prototype.myFilter = function(callback) {
// Only change code below this line
let newArray = [];
this.forEach(function(x) {
if (callback(x) == true) {
newArray.push(x);
}
});
// Only change code above this line
return newArray;
};
var new_s = s.myFilter(function(item) {
return item % 2 === 1;
});
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0
.
Challenge: Implement the filter Method on a Prototype
Link to the challenge: