Created
October 11, 2020 21:05
-
-
Save steveruizok/cd163c134b1d9d92cf36a4093fbd7b36 to your computer and use it in GitHub Desktop.
Map values.
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
export function remap<P, T>( | |
obj: { [key: string]: T }, | |
fn: (value: T, index: number) => P | |
): { [key: string]: P } { | |
return Object.fromEntries( | |
Object.entries(obj).map(([id, value], index) => [id, fn(value, index)]) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment