|
Last change
on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
620 bytes
|
| Line | |
|---|
| 1 | import { reduce } from './reduce.mjs';
|
|---|
| 2 | import { identity } from '../../function/identity.mjs';
|
|---|
| 3 | import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|---|
| 4 | import { isObjectLike } from '../predicate/isObjectLike.mjs';
|
|---|
| 5 | import { iteratee } from '../util/iteratee.mjs';
|
|---|
| 6 |
|
|---|
| 7 | function keyBy(collection, iteratee$1) {
|
|---|
| 8 | if (!isArrayLike(collection) && !isObjectLike(collection)) {
|
|---|
| 9 | return {};
|
|---|
| 10 | }
|
|---|
| 11 | const keyFn = iteratee(iteratee$1 ?? identity);
|
|---|
| 12 | return reduce(collection, (result, value) => {
|
|---|
| 13 | const key = keyFn(value);
|
|---|
| 14 | result[key] = value;
|
|---|
| 15 | return result;
|
|---|
| 16 | }, {});
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | export { keyBy };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.