A fair grouping mechanism for tournaments
npm install groupA simple pooling algorithm for group stages, ffa style tournaments or anything else that benefits from having seeds/weighted numbers split into fair groups.
``js
var group = require('group');
group(16, 4);
[ [ 1, 5, 12, 16 ],
[ 2, 6, 11, 15 ],
[ 3, 7, 10, 14 ],
[ 4, 8, 9, 13 ] ]
group(25, 5);
[ [ 1, 6, 11, 20, 25 ],
[ 2, 7, 12, 19, 24 ],
[ 3, 8, 13, 18, 23 ],
[ 4, 9, 14 17, 22 ],
[ 5, 10, 15, 16, 21 ] ]
`
- numPlayers === groupSize*numGroupsgroupSize % 2 === 0
-
You should always strive to satisfy the first condition.
If the groupSize is not even, then we cannot match up weighted pairs and the sum of seeds per group will differ by up to numGroups.
If the groupSize is even, then the sum of seeds per groups are equal across all groups.
`js`
group.minimalGroupSize(16, 4); // 4
group.minimalGroupSize(25, 5); // 5
group.minimalGroupSize(8, 5); // 4
group.minimalGroupSize(numPlayers, groupSize); // general
:`js
group.fromArray(['a','b','c','d','e','f','g','h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'], 4)
[ [ 'a', 'e', 'l', 'p' ],
[ 'b', 'f', 'k', 'o' ],
[ 'c', 'g', 'j', 'n' ],
[ 'd', 'h', 'i', 'm' ] ]
``