source: node_modules/es-toolkit/dist/array/groupBy.js

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

Added visualizations

  • Property mode set to 100644
File size: 444 bytes
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5function groupBy(arr, getKeyFromItem) {
6 const result = {};
7 for (let i = 0; i < arr.length; i++) {
8 const item = arr[i];
9 const key = getKeyFromItem(item, i, arr);
10 if (!Object.hasOwn(result, key)) {
11 result[key] = [];
12 }
13 result[key].push(item);
14 }
15 return result;
16}
17
18exports.groupBy = groupBy;
Note: See TracBrowser for help on using the repository browser.