The Tip That Didn't Add Up — JavaScript Bug Hunt
Inspired by the gig-economy payout scandals over vanishing cents: split a $1.00 tip among 3 drivers with floor(total/n) and one cent simply evaporates —…
- Language: JavaScript
- Layer: Backend
- Difficulty: Medium
- Concepts: Rounding, Money
- Modelled on: Gig-economy payouts
- Visible tests: the classic dollar-three-ways case conserves the cent; the sum is always exact; even divisions stay even
- Reward: 50 XP for a complete fix
Briefing
Inspired by the gig-economy payout scandals over vanishing cents: split a $1.00 tip among 3 drivers with floor(total/n) and one cent simply evaporates — times millions of orders.
split.js must conserve every cent: parts differ by at most one, extra cents go to the earliest parts, and the sum is exact.
Bug report
BUG-1CENT-TIP · Priority: High (press risk) · Reported by: payouts
splitEvenly(totalCents, n):
- returns n integers summing EXACTLY to totalCents
- parts differ by at most 1; earlier parts get the extra cents
Observed: splitEvenly(100, 3) -> [33, 33, 33]. One cent gone, every order.
Logs
[payout] reconciliation: -$8,214.66 this quarter in vanished remaindersThe code as shipped
src/pay/split.js (editable)
// Splits a tip evenly across n recipients.
exports.splitEvenly = function (totalCents, n) {
var each = Math.floor(totalCents / n);
var out = [];
for (var i = 0; i < n; i++) {
out.push(each);
}
return out;
};
Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More JavaScript bug hunts.