invert
Invert the keys and values of an object
94 bytes
Usage
Given an object returns a new object with the keys and values reversed.
import * as import _
_ from 'radashi'
const const powersByGod: { ra: string; loki: string; zeus: string;}
powersByGod = { ra: string
ra: 'sun', loki: string
loki: 'tricks', zeus: string
zeus: 'lightning',}
import _
_.invert<"ra" | "loki" | "zeus", string>(obj: Record<"ra" | "loki" | "zeus", string>): Record<string, "ra" | "loki" | "zeus">export invert
Returns a new object whose keys are the values of the given object
and its values are the keys of the given object.
invert(const powersByGod: { ra: string; loki: string; zeus: string;}
powersByGod) // => { sun: ra, tricks: loki, lightning: zeus }