Prototype: splitEqual(total,participants) requires nonnegative safe integer total and distinct nonempty names in a nonempty list. Preserve input; return plain object shares constructed in lexical name order, quotient plus one extra cent for first remainder names. Zero shares valid. Integer-index property names follow JavaScript enumeration rules even though remainder allocation uses lexical order.

Final: ExpenseSharing(members) copies valid fixed members with zero balances. addExpense(operationId,payer,total,participants) requires nonempty ID, positive total, group payer, and distinct nonempty participant subset; payer may be excluded. Credit payer total, debit shares. settle(operationId,debtor,creditor,amount) requires nonempty ID, two distinct members, positive amount, and sufficient debtor debt/creditor credit. Both validate structure first, then exact successful retry returns false before balance-dependent checks; any accepted ID reused with different data/method raises RangeError. Expense identity ignores participant order. Failures consume no ID. balances returns fresh plain object of every member, positive means owed; sum always zero, keys constructed lexically subject JS enumeration rules. suggestSettlements returns fresh [debtor,creditor,cents] pairs by alphabetic debtor/creditor greedy matching on copies, no mutations.

Every class is exported by name from exercise.mjs. Keep instances independent. Unless explicitly documented otherwise, input values have the stated collection/string types and do not contain null elements. Invalid calls preserve state; validate before mutation. Return fresh mutable snapshots unless stated otherwise.

Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
No results yet.

Complete the starter code, then run the checks.
Results and errors will appear here.