source: node_modules/es-toolkit/dist/compat/array/countBy.mjs

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 602 bytes
RevLine 
[a762898]1import { isArrayLike } from '../predicate/isArrayLike.mjs';
2import { iteratee } from '../util/iteratee.mjs';
3
4function countBy(collection, iteratee$1) {
5 if (collection == null) {
6 return {};
7 }
8 const array = isArrayLike(collection) ? Array.from(collection) : Object.values(collection);
9 const mapper = iteratee(iteratee$1 ?? undefined);
10 const result = Object.create(null);
11 for (let i = 0; i < array.length; i++) {
12 const item = array[i];
13 const key = mapper(item);
14 result[key] = (result[key] ?? 0) + 1;
15 }
16 return result;
17}
18
19export { countBy };
Note: See TracBrowser for help on using the repository browser.