DEV Community

Discussion on: Much needed filterMap in JavaScript

Collapse
 
johnsoncherian profile image
Johnson • Edited
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

Yes you got that right !!