all files / util/ filter.js

40% Statements 4/10
50% Branches 4/8
100% Functions 1/1
44.44% Lines 4/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16      1567× 1567× 1567×                  
import isFunction from './isFunction'
import forEach from './forEach'
 
export default function filter(iteratee, fn) {
  Iif (!iteratee) return []
  Eif (iteratee.constructor.prototype.filter && isFunction(iteratee.constructor.prototype.filter)) {
    return iteratee.filter(fn)
  }
  let result = []
  forEach(iteratee, (val, key) => {
    if (fn(val, key)) {
      result.push(val)
    }
  })
  return result
}