Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

pickBy.js 1.0KB

12345678910111213141516171819202122232425262728293031323334353637
  1. var arrayMap = require('./_arrayMap'),
  2. baseIteratee = require('./_baseIteratee'),
  3. basePickBy = require('./_basePickBy'),
  4. getAllKeysIn = require('./_getAllKeysIn');
  5. /**
  6. * Creates an object composed of the `object` properties `predicate` returns
  7. * truthy for. The predicate is invoked with two arguments: (value, key).
  8. *
  9. * @static
  10. * @memberOf _
  11. * @since 4.0.0
  12. * @category Object
  13. * @param {Object} object The source object.
  14. * @param {Function} [predicate=_.identity] The function invoked per property.
  15. * @returns {Object} Returns the new object.
  16. * @example
  17. *
  18. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  19. *
  20. * _.pickBy(object, _.isNumber);
  21. * // => { 'a': 1, 'c': 3 }
  22. */
  23. function pickBy(object, predicate) {
  24. if (object == null) {
  25. return {};
  26. }
  27. var props = arrayMap(getAllKeysIn(object), function(prop) {
  28. return [prop];
  29. });
  30. predicate = baseIteratee(predicate);
  31. return basePickBy(object, props, function(value, path) {
  32. return predicate(value, path[0]);
  33. });
  34. }
  35. module.exports = pickBy;