Skip to content

Instantly share code, notes, and snippets.

@steveruizok
Created October 11, 2020 21:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save steveruizok/cd163c134b1d9d92cf36a4093fbd7b36 to your computer and use it in GitHub Desktop.
Save steveruizok/cd163c134b1d9d92cf36a4093fbd7b36 to your computer and use it in GitHub Desktop.
Map values.
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