|
Last change
on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 6 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
263 bytes
|
| Rev | Line | |
|---|
| [a762898] | 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.