_baseFilter.js 590 B

123456789101112131415161718192021
  1. var baseEach = require('./_baseEach');
  2. /**
  3. * The base implementation of `_.filter` without support for iteratee shorthands.
  4. *
  5. * @private
  6. * @param {Array|Object} collection The collection to iterate over.
  7. * @param {Function} predicate The function invoked per iteration.
  8. * @returns {Array} Returns the new filtered array.
  9. */
  10. function baseFilter(collection, predicate) {
  11. var result = [];
  12. baseEach(collection, function(value, index, collection) {
  13. if (predicate(value, index, collection)) {
  14. result.push(value);
  15. }
  16. });
  17. return result;
  18. }
  19. module.exports = baseFilter;