It's a bit more generic operation "partition"
let groupBy = (f, coll) => {
let rf = (acc, el) => {
let id = f(el);
acc[id] = [... (acc[id] || []), el]
return acc
}
return coll.reduce(rf , {})
}
Can be used as partition as:
let {false: f, true: t} = groupBy( x => x == 2 , [1,2,3])
Maybe should we accumulate over an actual Map allowing f return any object (?!)
It's a bit more generic operation "partition"
Can be used as
partitionas:Maybe should we accumulate over an actual
Mapallowingfreturn any object (?!)