source:
node_modules/es-toolkit/dist/array/countBy.mjs
| Last change on this file was a762898, checked in by , 5 months ago | |
|---|---|
|
|
| File size: 263 bytes | |
| Line | |
|---|---|
| 1 | function countBy(arr, mapper) { |
| 2 | const result = {}; |
| 3 | for (let i = 0; i < arr.length; i++) { |
| 4 | const item = arr[i]; |
| 5 | const key = mapper(item, i, arr); |
| 6 | result[key] = (result[key] ?? 0) + 1; |
| 7 | } |
| 8 | return result; |
| 9 | } |
| 10 | |
| 11 | export { countBy }; |
Note:
See TracBrowser
for help on using the repository browser.
