Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions frontend/src/ts/test/test-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export function calculateWpmAndRaw(
withDecimalPoints?: true,
final = false,
testSecondsOverride?: number,
charsOverride?: CharCount,
): {
wpm: number;
raw: number;
Expand All @@ -124,7 +125,7 @@ export function calculateWpmAndRaw(
testSecondsOverride ??
calculateTestSeconds(TestState.isActive ? performance.now() : end);

const chars = countChars(final);
const chars = charsOverride ?? countChars(final);
const wpm = Numbers.roundTo2(
(chars.correctWordChars * (60 / testSeconds)) / 5,
);
Expand Down Expand Up @@ -341,9 +342,8 @@ export function calculateFinalStats(): Stats {
);
}

//todo: this counts chars twice - once here and once in calculateWpmAndRaw
const chars = countChars(true);
const { wpm, raw } = calculateWpmAndRaw(true, true, testSeconds);
const { wpm, raw } = calculateWpmAndRaw(true, true, testSeconds, chars);
const acc = Numbers.roundTo2(calculateAccuracy());
const ret = {
wpm: isNaN(wpm) ? 0 : wpm,
Expand Down
Loading