source: node_modules/es-toolkit/dist/array/groupBy.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: 348 bytes
Line 
1function groupBy(arr, getKeyFromItem) {
2 const result = {};
3 for (let i = 0; i < arr.length; i++) {
4 const item = arr[i];
5 const key = getKeyFromItem(item, i, arr);
6 if (!Object.hasOwn(result, key)) {
7 result[key] = [];
8 }
9 result[key].push(item);
10 }
11 return result;
12}
13
14export { groupBy };
Note: See TracBrowser for help on using the repository browser.