Skip to content

Commit

Permalink
fix issue where tally was always empty if no tallyDefinitions were pr…
Browse files Browse the repository at this point in the history
…ovided
  • Loading branch information
swantzter committed Nov 2, 2024
1 parent 6a4c3ec commit 116b912
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,17 @@ export function filterMarkStream <Schema extends string> (rawMarks: Readonly<Arr
}

export function normaliseTally <TallySchema extends string> (tallyDefinitions?: Readonly<Array<Readonly<JudgeTallyFieldDefinition<TallySchema>>>>, _tally?: Readonly<ScoreTally<TallySchema>>) {
const tally: ScoreTally<TallySchema> = {}
let tally: ScoreTally<TallySchema> = {}

for (const field of (tallyDefinitions ?? [])) {
const v = _tally?.[field.schema] ?? field.default ?? 0
if (typeof v !== 'number') continue
if (tallyDefinitions != null) {
for (const field of tallyDefinitions) {
const v = _tally?.[field.schema] ?? field.default ?? 0
if (typeof v !== 'number') continue

tally[field.schema] = clampNumber(v, field)
tally[field.schema] = clampNumber(v, field)
}
} else if (_tally != null) {
tally = { ..._tally }
}

return tally as Required<ScoreTally<TallySchema>>
Expand Down

0 comments on commit 116b912

Please sign in to comment.