Projekt

Obecné

Profil

Stáhnout (1.01 KB) Statistiky
| Větev: | Revize:
1
var arrayMap = require('./_arrayMap'),
2
    baseIteratee = require('./_baseIteratee'),
3
    basePickBy = require('./_basePickBy'),
4
    getAllKeysIn = require('./_getAllKeysIn');
5

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

    
37
module.exports = pickBy;
(450-450/571)