Skip to content

Commit 6f83eb8

Browse files
committed
better return type
1 parent 92ba447 commit 6f83eb8

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

frontend/src/ts/collections/results.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ export async function getUserAverage<M extends Mode>(
390390
last10Only: boolean;
391391
lastDayOnly: boolean;
392392
}>,
393-
): Promise<[number, number]> {
393+
): Promise<{ wpm: number; acc: number }> {
394394
const activeTagIds = getSnapshot()
395395
?.tags.filter((it) => it.active === true)
396396
.map((it) => it._id);
@@ -423,6 +423,7 @@ export async function getUserAverage<M extends Mode>(
423423
return query.select(({ r }) => ({ wpm: avg(r.wpm), acc: avg(r.acc) }));
424424
}).toArrayWhenReady();
425425

426-
if (result.length !== 1) return [0, 0];
427-
return [result[0]?.wpm ?? 0, result[0]?.acc ?? 0];
426+
return result.length === 1 && result[0] !== undefined
427+
? result[0]
428+
: { wpm: 0, acc: 0 };
428429
}

frontend/src/ts/elements/last-10-average.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ let averageAcc = 0;
1010
export async function update(): Promise<void> {
1111
const mode2 = Misc.getMode2(Config, TestWords.currentQuote);
1212

13-
const [wpm, acc] = (
14-
await getUserAverage({ ...Config, mode2, last10Only: true })
15-
).map(Numbers.roundTo2) as [number, number];
13+
const average = await getUserAverage({
14+
...Config,
15+
mode2,
16+
last10Only: true,
17+
});
18+
const wpm = Numbers.roundTo2(average.wpm);
19+
const acc = Numbers.roundTo2(average.acc);
1620

1721
averageWPM = Config.alwaysShowDecimalPlaces ? wpm : Math.round(wpm);
1822
averageAcc = Config.alwaysShowDecimalPlaces ? acc : Math.floor(acc);

frontend/src/ts/test/pace-caret.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,13 @@ export async function init(): Promise<void> {
8383
Config.lazyMode,
8484
);
8585
} else if (Config.paceCaret === "average") {
86-
[wpm] = await getUserAverage({ ...Config, mode2, last10Only: true });
87-
88-
wpm = Math.round(wpm);
86+
wpm = Math.round(
87+
(await getUserAverage({ ...Config, mode2, last10Only: true })).wpm,
88+
);
8989
} else if (Config.paceCaret === "daily") {
90-
[wpm] = await getUserAverage({ ...Config, mode2, lastDayOnly: true });
91-
wpm = Math.round(wpm);
90+
wpm = Math.round(
91+
(await getUserAverage({ ...Config, mode2, lastDayOnly: true })).wpm,
92+
);
9293
} else if (Config.paceCaret === "custom") {
9394
wpm = Config.paceCaretCustomSpeed;
9495
} else if (Config.paceCaret === "last" || TestState.isPaceRepeat) {

0 commit comments

Comments
 (0)