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.
The key function can return any string. A classic example is grouping numbers as 'even' or 'odd'.
Challenge: Implement groupEvenOdd(nums) that groups numbers into even and odd.
groupEvenOdd([1, 2, 3, 4]) // β { odd: [1, 3], even: [2, 4] }