Split a bill between participants
Node · Node · intermediate · greenfield
Adds the bill-splitting helper for group billing: divides the total evenly and rounds each share to cents. Straightforward math, verified with an even split.
Group billing: totals up to $10,000, groups of 2–20 people. The shares are what actually gets charged to each card.
Requirements
- Split a bill total evenly between the participants.
- Each share is in dollars with at most two decimal places.
- The shares must sum exactly to the charged total — no cent may appear or disappear.
Files touched
- src/services/splitBill.js
--- src/services/splitBill.js
+function splitBill(totalDollars, participantIds) {
+ const each = +(totalDollars / participantIds.length).toFixed(2);
+ return participantIds.map((id) => ({ participantId: id, amount: each }));
+}
+
+module.exports = { splitBill };