Two servers work the same hours and have five cents to split. Their exact shares are 2.5 cents each. Calling Math.round on both pays out six cents. The largest-remainder method pays three cents to the first worker and two to the second. The shift ledger balances at five.
Carry the remainder through the ledger
For each worker, multiply the pool in cents by that worker's weight. Divide by the sum of the weights to get a whole-cent quotient and a remainder. After assigning the quotients, award one cent at a time in descending remainder order. The input list breaks ties, so keep that order in the shift record if you need to replay a payout.
In hours mode the weight is hours. In points mode it is hours times role points. The implementation converts both factors to scaled integers and uses BigInt for intermediate products. A pool of 101 cents with weights of 3 and 1.5 pays 67 and 34 cents.
Hybrid mode first apportions the distributable pool into role buckets and a base bucket. Each bucket then runs the same algorithm using only its own workers. The 64-worker fixture starts with $100.01, including $80.00 in card tips. A 2.75% processing fee, when applicable law permits it, leaves $97.81 to allocate.
| Bucket | Share | Budget |
|---|---|---|
| Bar | 15% | $14.67 |
| Busser | 10% | $9.78 |
| Runner | 5% | $4.89 |
| Base | 70% | $68.47 |
The base bucket had the largest fractional remainder in this fixture. Rounding at the bucket level first protects the dollar budgets when a job group has several recipients.
Test the payouts, then measure the splitter
Run this block from the library checkout with Node.js 20 or later. It verifies the payouts and pool totals before timing, warms up each case, then reports the median of five samples of 20,000 splits. It measures the full split call on prebuilt inputs. The 64-worker fixture tests larger rosters and a second allocation stage together. MIT source repository
node --input-type=module <<'JS'
import assert from 'node:assert/strict';
import { performance } from 'node:perf_hooks';
import { checkTipCreditShortfall, splitTipPool } from './src/index.js';
const worker = (id, hours, role = 'server', rolePoints = 1) => ({
id, hours, role, rolePoints, classification: 'employee',
});
const hours = { grossPoolCents: 5, workers: [worker('A', 1), worker('B', 1)] };
const points = {
grossPoolCents: 101, mode: 'points',
workers: [worker('A', 2.5, 'server', 1.2), worker('B', 3, 'bar', 0.5)],
};
const hybrid = {
grossPoolCents: 10_001, mode: 'hybrid',
creditCardFee: { cardTipsCents: 8_000, rateBps: 275, statePermitsDeduction: true },
tipOutBpsByRole: { bar: 1_500, busser: 1_000, runner: 500 },
workers: Array.from({ length: 64 }, (_, i) => worker(
`W${i}`, 8, i < 40 ? 'server' : ['bar', 'busser', 'runner'][Math.floor((i - 40) / 8)],
)),
};
const cases = [
{ name: 'hours / 2', input: hours, total: 5, first: 3 },
{ name: 'points / 2', input: points, total: 101, first: 67 },
{ name: 'hybrid / 64', input: hybrid, total: 9_781, first: 172 },
];
assert.equal(2 * Math.round(5 / 2), 6);
for (const { input, total, first } of cases) {
const result = splitTipPool(input);
assert.equal(result.distributablePoolCents, total);
assert.equal(result.allocations.reduce((sum, row) => sum + row.cents, 0), total);
assert.equal(result.allocations[0].cents, first);
assert.equal(result.distributablePoolCents + result.creditCardFeeCents, input.grossPoolCents);
}
const hybridPlan = splitTipPool(hybrid);
assert.deepEqual(hybridPlan.tipOuts.map(({ cents }) => cents), [1_467, 978, 489]);
assert.equal(hybridPlan.basePoolCents, 6_847);
assert.throws(() => splitTipPool({
...hours, workers: [{ ...hours.workers[0], classification: 'supervisor' }],
}), /203\(m\)\(2\)\(B\)/);
assert.equal(checkTipCreditShortfall({
hours: 8, cashWagesCents: 1_704, retainedTipsCents: 2_500, tipCreditEligible: true,
}).shortfallCents, 1_596);
const iterations = 20_000;
const measurements = [];
for (const { name, input, total, first } of cases) {
for (let i = 0; i < 4_000; i++) splitTipPool(input);
const samples = [];
for (let sample = 0; sample < 5; sample++) {
let checksum = 0;
const start = performance.now();
for (let i = 0; i < iterations; i++) {
const result = splitTipPool(input);
checksum += result.distributablePoolCents + result.allocations[0].cents;
}
samples.push(performance.now() - start);
assert.equal(checksum, (total + first) * iterations);
}
const medianMs = samples.sort((a, b) => a - b)[2];
measurements.push({
name, iterations, medianMs: Number(medianMs.toFixed(2)),
splitsPerSecond: Math.round(iterations * 1_000 / medianMs),
});
}
console.log(process.version, process.platform, process.arch);
console.table(measurements);
JS
On arm64 macOS with Node.js v24.15.0, one run produced the following medians.
| Fixture | Median for 20,000 splits | Splits per second |
|---|---|---|
| Hours, 2 workers | 18.43 ms | 1,085,062 |
| Points, 2 workers | 33.12 ms | 603,951 |
| Hybrid, 64 workers | 634.97 ms | 31,497 |
The splitter computes a quotient and a remainder for each weight. If it has leftover cents, sorting those remainders makes a round of allocation O(n log n) in the worst case. The hybrid line measures both bucket allocation and the work within each bucket.
Check the cash wage after the split
The benchmark also exercises a separate straight-time wage check. For an eligible employee with eight hours, $17.04 in cash wages and $25.00 in retained tips, a $58.00 wage target leaves a $15.96 cash top-up. The function limits the usable tip credit to the actual retained tips, the configured hourly cap, and the remaining wage gap. Supply the rates and eligibility that apply to your workers.
The splitter rejects anyone classified as a manager or supervisor on the recipient roster under 29 U.S.C. 203(m)(2)(B). Classify by duties before running the split. Keep eligibility and permission for card-fee deductions in the input record so payroll can review the assumptions next to the exact payouts. Interactive GitHub Pages demo · Tip pool calculator · Banquet event order tools
Top comments (0)