JavaScript · Advanced · Ticket 4Ticket #40 · from Lena Fischer, Finance & Ops
  1. Example
  2. Warm-up 1
  3. Warm-up 2
  4. Ticket
Brief
NEW TICKET#40 · Payments

Split a payment so the cents add up

Lena Fischer · Finance & Ops
Opened today

“When a client pays part of an invoice, we split the payment across its lines in proportion to each line's total, so the accounts show what was paid for. The shares are in whole cents and must add up to exactly the payment. Right now each share is rounded on its own: $1.00 over three equal lines records 99 cents. Fix it this way: round every share down, then give the cents left over, one each, to the lines with the biggest fraction left over; on a tie, the earlier line first.”

YOUR PLAN
  1. 1Watch an example2 min
  2. 2Warm-up 11 min
  3. 3Warm-up 21 min
  4. 4Fix the ticket26 min
BY THE END YOU CAN
  • See how rounding each part loses or invents cents
  • Round down, then hand out what's left
  • Sort indexes by a computed value
About 30 minutes
Four short steps. Nothing is timed, and you can leave any time.