mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-03-12 23:20:25 +08:00
Merge pull request #1238 from dewblackio2/master
Fixed undefined (NaN) issue with Personal Average Pace Caret when using quote mode
This commit is contained in:
commit
e0099607ea
1 changed files with 28 additions and 5 deletions
33
src/js/db.js
33
src/js/db.js
|
@ -212,23 +212,46 @@ export async function getUserAverageWpm10(
|
|||
function cont() {
|
||||
let wpmSum = 0;
|
||||
let count = 0;
|
||||
let last10Wpm = 0;
|
||||
let last10Count = 0;
|
||||
// You have to use every so you can break out of the loop
|
||||
dbSnapshot.results.every((result) => {
|
||||
if (
|
||||
result.mode == mode &&
|
||||
result.mode2 == mode2 &&
|
||||
result.punctuation == punctuation &&
|
||||
result.language == language &&
|
||||
result.difficulty == difficulty
|
||||
) {
|
||||
wpmSum += result.wpm;
|
||||
count++;
|
||||
if (count >= 10) {
|
||||
return false;
|
||||
// Continue if the mode2 doesn't match unless it's a quote.
|
||||
if (result.mode2 != mode2 && mode != "quote") {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Grab the most recent 10 wpm's for the current mode.
|
||||
if (last10Count < 10) {
|
||||
last10Wpm += result.wpm;
|
||||
last10Count++;
|
||||
}
|
||||
|
||||
// Check mode2 matches and append, for quotes this is the quote id.
|
||||
if (result.mode2 == mode2) {
|
||||
wpmSum += result.wpm;
|
||||
count++;
|
||||
if (count >= 10) {
|
||||
// Break out of every loop since we a maximum of the last 10 wpm results.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
// Return the last 10 average wpm for quote if the current quote id has never been completed before by the user.
|
||||
if (count == 0 && mode == "quote") {
|
||||
return Math.round(last10Wpm / last10Count);
|
||||
}
|
||||
|
||||
// Return the average wpm of the last 10 completions for the targeted test mode.
|
||||
return Math.round(wpmSum / count);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue