Created
September 21, 2020 17:00
-
-
Save carmour24/39be3e219d55e939bece592094cf7351 to your computer and use it in GitHub Desktop.
Quick method for mapping the entries in a map resulting in a new map.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const mapMap = (inputMap, mapping) => { | |
| const _map = (iterator, mapping) => { | |
| const entry = iterator.next() | |
| return entry.done | |
| ? [] | |
| : [[entry.value[0], mapping(entry.value)], ..._map(iterator, mapping)] | |
| } | |
| const iterator = inputMap[Symbol.iterator]() | |
| const mappingResultEntries = _map(iterator, mapping) | |
| return new Map(mappingResultEntries) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment