main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[d565449] | 1 | import arrayMap from './_arrayMap.js';
|
---|
| 2 | import baseIteratee from './_baseIteratee.js';
|
---|
| 3 | import basePickBy from './_basePickBy.js';
|
---|
| 4 | import getAllKeysIn from './_getAllKeysIn.js';
|
---|
| 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 | export default pickBy;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.