Intermediate
Write groupBy
groupBy should sort a list into piles, one per key. The current version works only for unknown items and string keys, so the callback (w) => w[0] doesn't even compile.
Make it generic: T for the item, K extends PropertyKey for the key that the callback returns. The result is a Partial<Record<K, T[]>>: not every key has a pile.
What Check tests
- Your code has no type errors
- The console prints the three piles
- Numbers can be grouped by a text key
- The callback sees the real item type
- A boolean key is rejected
- A pile may be missing
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Runs in your browser. Your code is saved here.
Press Run to see the page.
Console
Nothing printed yet.