JS Built-ins
TypeScriptintermediate

Utility Types β€” invertRecord

πŸ“– Usage Example
invertRecord({ a: '1', b: '2' })   // β†’ { '1': 'a', '2': 'b' }

invertRecord swaps keys and values in an object, producing the inverse mapping.

Utility Types: Invert Keys and Values

Challenge: Implement invertRecord(obj: Record<string, string>): Record<string, string> swapping each key-value pair.

invertRecord({ a: 'x', b: 'y' })  // β†’ { x: 'a', y: 'b' }
πŸ’‘ Hints (1)
  • β€’ Object.entries gives [key, value] pairs you can swap.