|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
1.0 KB
|
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * Creates a new Map with the same values but with keys transformed by the provided function.
|
|---|
| 3 | *
|
|---|
| 4 | * This function takes a Map and a function that generates a new key from each value-key pair.
|
|---|
| 5 | * It returns a new Map where the keys are the result of applying the function to each entry,
|
|---|
| 6 | * while the values remain the same.
|
|---|
| 7 | *
|
|---|
| 8 | * @template K - The type of keys in the Map.
|
|---|
| 9 | * @template V - The type of values in the Map.
|
|---|
| 10 | * @param {Map<K, V>} map - The Map to transform.
|
|---|
| 11 | * @param {(value: V, key: K, object: Map<K, V>) => K} getNewKey - A function that generates a new key from a value-key pair.
|
|---|
| 12 | * @returns {Map<K, V>} A new Map with transformed keys and the same values.
|
|---|
| 13 | *
|
|---|
| 14 | * @example
|
|---|
| 15 | * const map = new Map([
|
|---|
| 16 | * ['a', 1],
|
|---|
| 17 | * ['b', 2],
|
|---|
| 18 | * ['c', 3]
|
|---|
| 19 | * ]);
|
|---|
| 20 | * const result = mapKeys(map, (value, key) => key.toUpperCase());
|
|---|
| 21 | * // result will be:
|
|---|
| 22 | * // Map(3) {
|
|---|
| 23 | * // 'A' => 1,
|
|---|
| 24 | * // 'B' => 2,
|
|---|
| 25 | * // 'C' => 3
|
|---|
| 26 | * // }
|
|---|
| 27 | */
|
|---|
| 28 | declare function mapKeys<K, V>(map: Map<K, V>, getNewKey: (value: V, key: K, object: Map<K, V>) => K): Map<K, V>;
|
|---|
| 29 |
|
|---|
| 30 | export { mapKeys };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.