Passenger tickets grouped in the yard: Object.groupBy, Map.groupBy or a hand-written reduce, each group a new train carrying the very same crates, and a…
The key idea
One call, fn gives each item’s key, Map for keys that are not strings
Try it in this playground
Group by city Run t => t.kota to the end: every ticket to its city’s train.
Number keys: Object, then Map With t => t.kelas, compare the key types on the board: string in Object, number in Map.
Object keys Use t => ({ kota: t.kota }) with Object.groupBy: everything ends up in one group.
reduce and constructor Run the reduce with {} on the city 'constructor': the engine’s TypeError.