|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
905 bytes
|
| Line | |
|---|
| 1 | import { keysIn } from './keysIn.mjs';
|
|---|
| 2 | import { range } from '../../math/range.mjs';
|
|---|
| 3 | import { getSymbolsIn } from '../_internal/getSymbolsIn.mjs';
|
|---|
| 4 | import { identity } from '../function/identity.mjs';
|
|---|
| 5 | import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|---|
| 6 | import { isSymbol } from '../predicate/isSymbol.mjs';
|
|---|
| 7 | import { iteratee } from '../util/iteratee.mjs';
|
|---|
| 8 |
|
|---|
| 9 | function pickBy(obj, shouldPick) {
|
|---|
| 10 | if (obj == null) {
|
|---|
| 11 | return {};
|
|---|
| 12 | }
|
|---|
| 13 | const predicate = iteratee(shouldPick ?? identity);
|
|---|
| 14 | const result = {};
|
|---|
| 15 | const keys = isArrayLike(obj) ? range(0, obj.length) : [...keysIn(obj), ...getSymbolsIn(obj)];
|
|---|
| 16 | for (let i = 0; i < keys.length; i++) {
|
|---|
| 17 | const key = (isSymbol(keys[i]) ? keys[i] : keys[i].toString());
|
|---|
| 18 | const value = obj[key];
|
|---|
| 19 | if (predicate(value, key, obj)) {
|
|---|
| 20 | result[key] = value;
|
|---|
| 21 | }
|
|---|
| 22 | }
|
|---|
| 23 | return result;
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | export { pickBy };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.