Functional Programming - Implement the filter Method on a Prototype

Tell us what’s happening:
Describe your issue in detail here.
Do i type the while loop?
Your code so far

Array.prototype.myFilter = function(callback) {
  const newArray = [];
  // Only change code below this line
for (let i = 0; i < this.length; i++) {
  const result = callback(this[i], i, this);
  // Only change code above this line
  return newArray;
const result = [1, 1, 2, 5, 2].myFilter((element, index, array)=>  array.indexOf(element) === index);

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Functional Programming - Implement the filter Method on a Prototype

Link to the challenge:

What do you mean? Take another look at the challenge instructions. callback function is supposed to be used as a check if specific element should be included in the filtered array or not.


Everything looks fine, except that you add the result(true or false) of each element into the newArray and not the element based on thier return value.

Check whether the result is true or false using an “if” statement. If true push that element to newArray, else ignore it.


Its been almost 3 months since you’ve posted this, and yet I hope my reply helped you in some way.

! Happy coding :woman_technologist:.

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