|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
719 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | const isArrayLike = require('../predicate/isArrayLike.js');
|
|---|
| 6 | const iteratee = require('../util/iteratee.js');
|
|---|
| 7 |
|
|---|
| 8 | function countBy(collection, iteratee$1) {
|
|---|
| 9 | if (collection == null) {
|
|---|
| 10 | return {};
|
|---|
| 11 | }
|
|---|
| 12 | const array = isArrayLike.isArrayLike(collection) ? Array.from(collection) : Object.values(collection);
|
|---|
| 13 | const mapper = iteratee.iteratee(iteratee$1 ?? undefined);
|
|---|
| 14 | const result = Object.create(null);
|
|---|
| 15 | for (let i = 0; i < array.length; i++) {
|
|---|
| 16 | const item = array[i];
|
|---|
| 17 | const key = mapper(item);
|
|---|
| 18 | result[key] = (result[key] ?? 0) + 1;
|
|---|
| 19 | }
|
|---|
| 20 | return result;
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | exports.countBy = countBy;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.