Function: distribute()
ts
function distribute(total, weights): number[];Split total by weight ratios; remainder goes to largest fractional parts (largest remainder method). 按权重比例分配总量;余数按最大余额法分配。
Parameters
| Parameter | Type | Description |
|---|---|---|
total | number | Amount to split / 待分配总量 |
weights | number[] | Non-negative weights / 非负权重 |
Returns
number[]
Allocated parts summing to total / 分配结果,之和为 total
Example
ts
distribute(100, [1, 2, 2]) // => [20, 40, 40]Since
1.0.0