|
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.1 KB
|
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * Creates a new Map with the same keys but with values transformed by the provided function.
|
|---|
| 3 | *
|
|---|
| 4 | * This function takes a Map and a function that generates a new value from each value-key pair.
|
|---|
| 5 | * It returns a new Map where the values are the result of applying the function to each entry,
|
|---|
| 6 | * while the keys 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>) => V} getNewValue - A function that generates a new value from a value-key pair.
|
|---|
| 12 | * @returns {Map<K, V>} A new Map with the same keys and transformed values.
|
|---|
| 13 | *
|
|---|
| 14 | * @example
|
|---|
| 15 | * const map = new Map([
|
|---|
| 16 | * ['a', 1],
|
|---|
| 17 | * ['b', 2],
|
|---|
| 18 | * ['c', 3]
|
|---|
| 19 | * ]);
|
|---|
| 20 | * const result = mapValues(map, (value) => value * 2);
|
|---|
| 21 | * // result will be:
|
|---|
| 22 | * // Map(3) {
|
|---|
| 23 | * // 'a' => 2,
|
|---|
| 24 | * // 'b' => 4,
|
|---|
| 25 | * // 'c' => 6
|
|---|
| 26 | * // }
|
|---|
| 27 | */
|
|---|
| 28 | declare function mapValues<K, V, R>(map: Map<K, V>, getNewValue: (value: V, key: K, object: Map<K, V>) => R): Map<K, R>;
|
|---|
| 29 |
|
|---|
| 30 | export { mapValues };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.