Home > @wixc3/common > partition
Partition unordered data into buckets of similar total weight
Signature:
export declare function partition<T>(data: T[], bucketsCount: number, predicate: (item: T) => number): T[][];
Parameter | Type | Description |
---|---|---|
data | T\[\] | |
bucketsCount | number | |
predicate | (item: T) => number | maps a data items to weight |
Returns:
T[][]
buckets of similar total weight (sorted by weights, descending)
partition([1, 2, 3], 2, (i) => i)) // [[3], [2, 1]];