Tell us what’s happening:
Regarding the solution, I wanted to ask why we loop through (this[i], i, this).
Why isn’t it just this[i]?
Your code so far
Array.prototype.myFilter = function(callback) {
const newArray = [];
for (let i = 0; i < this.length; i++) {
if (Boolean(callback(this[i], i, this)) === true) {
newArray.push(this[i]);
}
}
return newArray;
};
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36
Challenge: Functional Programming - Implement the filter Method on a Prototype
Link to the challenge: