countBy
Import from @varavel/vdl-plugin-sdk/utils/sets.
Counts the occurrences of items in a Set based on a transformation function.
This function takes a Set and a function that generates a key from each value. It returns a Map with the generated keys and their counts as values. The count is incremented for each element for which the transformation produces the same key.
Type Parameters
| Type Parameter | Description |
|---|---|
T |
The type of elements in the Set. |
K |
The type of keys produced by the transformation function. |
Parameters
| Parameter | Type | Description |
|---|---|---|
set |
Set\<T> |
The Set to count occurrences from. |
mapper |
(value, value2, set) => K |
The function to produce a key for counting. |
Returns
Map\<K, number>
A Map containing the mapped keys and their counts.