Polyfill of Array.filter

Array.prototype.filterPolyfill = function (condition) {
  const output = [];
  this.forEach((num, index) => {
    if (condition(num, index, this)) {
      output.push(num);
    }
  });
  return output;
};

const ans = [1, 2, 3, 4, 5].filterPolyfill((num) => num >= 3);
console.log(ans);

// Output:
[ 3, 4, 5 ]