pickBy.js 774 B

123456789101112131415161718192021222324252627
  1. var baseIteratee = require('./_baseIteratee'),
  2. basePickBy = require('./_basePickBy');
  3. /**
  4. * Creates an object composed of the `object` properties `predicate` returns
  5. * truthy for. The predicate is invoked with two arguments: (value, key).
  6. *
  7. * @static
  8. * @memberOf _
  9. * @since 4.0.0
  10. * @category Object
  11. * @param {Object} object The source object.
  12. * @param {Array|Function|Object|string} [predicate=_.identity]
  13. * The function invoked per property.
  14. * @returns {Object} Returns the new object.
  15. * @example
  16. *
  17. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  18. *
  19. * _.pickBy(object, _.isNumber);
  20. * // => { 'a': 1, 'c': 3 }
  21. */
  22. function pickBy(object, predicate) {
  23. return object == null ? {} : basePickBy(object, baseIteratee(predicate));
  24. }
  25. module.exports = pickBy;