UNPKG

map-fns

Version:

<h1 align="center"> <code>map-fns</code> </h1>

20 lines (18 loc) 630 B
/** * Creates a new `map` populated with every key in the original `map` where the * value of each key `k` in the new map is the return value of `fn(map[k])`. * * @param map The original map. * @param fn A function that takes a single argument `map[k]` and returns the value of `newMap[k]`. * @returns A new `map` where `map[k]` is the result of `fn(map[k])`. */ function mapMap(map, fn) { var obj = {}; var keys = Object.keys(map); for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) { var key = keys_1[_i]; obj[key] = fn(map[key]); } return obj; } export { mapMap as default };