Javascript Array filter(fn)

Description

Javascript Array filter(fn)




Array.prototype.filter = function(fn){
    var self = this;
    var arr = [];
    for(var i=0; i<self.length; i++){
        if (fn(self[i])){
            arr.push(self[i]);//from  w ww  .ja v a  2s.c o m
        }
    }
    return arr;
};

module.exports.isFunction = function( obj ) {
    return toString.call(obj) === "[object Function]";
};

module.exports.isArray = function( obj ) {
    return toString.call(obj) === "[object Array]";
};



PreviousNext

Related