Functional Programming - Implement the filter Method on a Prototype

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:

Hi there and welcome to the forum!

I have spoilered this solution as we try to avoid solutions being posted on the forum.
Have you tried solving this for yourself yet?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.