source:
node_modules/es-toolkit/dist/set/countBy.mjs
| Last change on this file was a762898, checked in by , 5 months ago | |
|---|---|
|
|
| File size: 259 bytes | |
| Line | |
|---|---|
| 1 | function countBy(set, mapper) { |
| 2 | const result = new Map(); |
| 3 | for (const value of set) { |
| 4 | const mappedKey = mapper(value, value, set); |
| 5 | result.set(mappedKey, (result.get(mappedKey) ?? 0) + 1); |
| 6 | } |
| 7 | return result; |
| 8 | } |
| 9 | |
| 10 | export { countBy }; |
Note:
See TracBrowser
for help on using the repository browser.
