Javascript String filter(func)

Description

Javascript String filter(func)

String.prototype.filter = function(func) {
  str = this.split("");
  var ans = [];//  ww w  .j a  va2s.  c  om
  str.forEach(function(x) {
    if (func(x)) {
      ans.push(x);
    };
  });
  return ans;
};



PreviousNext

Related