🎉 init

This commit is contained in:
2026-07-01 15:43:18 +02:00
commit 2f492c55be
64 changed files with 11645 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
import type { ParticipantId } from '../types'
/**
* Splits amountCents equally among participantIds. Any remainder cents (from
* integer division) go one-each to the first participants in the given
* order, so the shares always sum exactly back to amountCents.
*/
export function computeSplit(amountCents: number, participantIds: ParticipantId[]): Record<ParticipantId, number> {
if (participantIds.length === 0) {
throw new Error('computeSplit requires at least one participant')
}
const base = Math.floor(amountCents / participantIds.length)
const remainder = amountCents - base * participantIds.length
const shares: Record<ParticipantId, number> = {}
participantIds.forEach((id, index) => {
shares[id] = base + (index < remainder ? 1 : 0)
})
return shares
}