loading...

Discussion on: Much needed filterMap in JavaScript

Collapse
johnsoncherian profile image
johnsoncherian
Array.prototype.filterMap = function(filter) {
   const r = [];
   for(let i=0; i<this.length; i++) {
      const item = filter(this[i], i, this);
      if (item !== undefined) {
         r.push(item);
      }
   }
   return item; // should be `return r`. right.?
};```

Collapse
akashkava profile image
Akash Kava Author

Yes you got that right !!