https://github.com/kormanowsky/distrib
Functions to distribute numbers or objects between groups
https://github.com/kormanowsky/distrib
Last synced: 6 months ago
JSON representation
Functions to distribute numbers or objects between groups
- Host: GitHub
- URL: https://github.com/kormanowsky/distrib
- Owner: kormanowsky
- Created: 2024-10-02T21:32:55.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-10-03T19:56:53.000Z (almost 2 years ago)
- Last Synced: 2025-10-11T07:58:08.162Z (10 months ago)
- Language: TypeScript
- Homepage:
- Size: 85.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# distrib
Functions to distribute numbers or objects between groups
## Usage
```typescript
import {distrib, distribObjects} from '@kormanowsky/distrib';
// Distribute ten 10's into at most 4 groups
// groups = [[10, 10, 10], [10, 10, 10], [10, 10], [10, 10]]
const groups = distrib([10, 10, 10, 10, 10, 10, 10, 10, 10, 10], 4);
// Distribute five objects into at most 3 groups
// objGroups = [[{x: 10}, {x: 10}], [{x:10}, {x: 10}], [{x: 10}]]
const objGroups = distribObjects(
[{x: 10}, {x: 10}, {x: 10}, {x:10}],
(obj) => obj.x,
3
);
```