Object.groupByintermediate// Group array items by a computed key
const items = [{ type: 'a', v: 1 }, { type: 'b', v: 2 }, { type: 'a', v: 3 }]
Object.groupBy(items, item => item.type)
// β { a: [{...}, {...}], b: [{...}] }Use Object.groupBy() to group an array's elements into an object keyed by a value returned from a callback.
You can derive the group key from any property of the item. Grouping words by their first letter is a natural example.
Challenge: Implement groupByFirstLetter(words) that groups words by their first character.
groupByFirstLetter(['apple', 'ant', 'banana'])
// β { a: ['apple', 'ant'], b: ['banana'] }