Open
Description
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 (?!)
Metadata
Metadata
Assignees
Labels
No labels