|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
904 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | const identity = require('../../function/identity.js');
|
|---|
| 6 | const isNil = require('../../predicate/isNil.js');
|
|---|
| 7 | const iteratee = require('../util/iteratee.js');
|
|---|
| 8 |
|
|---|
| 9 | function invertBy(object, iteratee$1) {
|
|---|
| 10 | const result = {};
|
|---|
| 11 | if (isNil.isNil(object)) {
|
|---|
| 12 | return result;
|
|---|
| 13 | }
|
|---|
| 14 | if (iteratee$1 == null) {
|
|---|
| 15 | iteratee$1 = identity.identity;
|
|---|
| 16 | }
|
|---|
| 17 | const keys = Object.keys(object);
|
|---|
| 18 | const getString = iteratee.iteratee(iteratee$1);
|
|---|
| 19 | for (let i = 0; i < keys.length; i++) {
|
|---|
| 20 | const key = keys[i];
|
|---|
| 21 | const value = object[key];
|
|---|
| 22 | const valueStr = getString(value);
|
|---|
| 23 | if (Array.isArray(result[valueStr])) {
|
|---|
| 24 | result[valueStr].push(key);
|
|---|
| 25 | }
|
|---|
| 26 | else {
|
|---|
| 27 | result[valueStr] = [key];
|
|---|
| 28 | }
|
|---|
| 29 | }
|
|---|
| 30 | return result;
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | exports.invertBy = invertBy;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.