JS Built-ins
TypeScriptadvanced

Advanced β€” groupByMultiple

πŸ“– Usage Example
groupByMultiple(
  [{ type: 'a', color: 'red' }],
  ['type', 'color']
)

groupByMultiple creates nested groups by applying multiple discriminator keys sequentially.

Advanced: Multi-Key Grouping

Challenge: Implement groupByMultiple<T extends object>(arr: T[], keys: (keyof T)[]): Record<string, T[]> creating a compound group key from multiple fields.

groupByMultiple([{a:1,b:'x'},{a:1,b:'y'},{a:2,b:'x'}], ['a','b'])
// { '1-x': [...], '1-y': [...], '2-x': [...] }
πŸ’‘ Hints (1)
  • β€’ Join the values at each key with a separator to form the compound key.