Please explain this code line by line.
.myFilter is equal to a function so why call “function(item)”?
Is “function(item)” going to into where is says “callback” above so
it would be: "Array.prototype.myFilter=function(function(item)){…?
If this is correct, then what is the function being called inside the function?
I am confused.
Is “Callback” equal to “function(item)”?
In the “for” loop, what is “this” equal to?
“callback” is not a function but a placeholder or variable.
Why are we doing “Callback(this[i] === true)”?
Recommendations to help me understand this section of Functional Programming?
It seems like it switched to another language once I started this section.
I have done fine until I hit this section and am not understanding any section nor
any solution provided for this Functional Programming section.
I did a tende and it has issues working for me most times to separate out the code.
let s = [23,65,98,5];
Array.prototype.myFilter = function(callback) {
var newArray = [];
// Add your code below this line
for (let i = 0; i < this.length; i++) {
if (callback(this[i]) === true) {
newArray.push(this[i]);
}
}
// Add your code above this line
return newArray;
};
var new_s = s.myFilter(function(item) {
return item % 2 === 1;
});