Javascript Array select(fun)

Description

Javascript Array select(fun)

Array.prototype.select = function(fun) {
  return this.reduce(function(res, el) {
    if(fun(el)) {
      res.push(el);/*from   w  w  w  .j a v a2s . c  o  m*/
    };
    return res;
  }, []);
}



PreviousNext

Related