Last active
January 9, 2019 22:50
-
-
Save tjjfvi/218f5336758592eb6634c2ba31f5660e to your computer and use it in GitHub Desktop.
Object.mapEntries, Object.mapValues, Object.mapKeys
This file contains 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
Object.mapEntries = (obj, fn) => | |
Object.assign({}, ...Object.entries(obj).map(e => fn(e, obj)).map(([k, v]) => ({ [k]: v }))); | |
Object.mapValues = (obj, fn) => | |
Object.mapEntries(obj, ([k, v]) => [k, fn(v, obj)]); | |
Object.mapKeys = (obj, fn) => | |
Object.mapEntries(obj, ([k, v]) => [fn(k, obj), v]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment