Skip to content
Open
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ export class ResultCalculationService {
const strippedCode = Challenge.getStrippedCode(code);
const cps = strippedCode.length / timeSeconds;
const cpm = cps * 60;
const words = strippedCode.trim().split(' ');
if (words.length === 0) { // Avoid division by zero
return 0;
}
const totalWordLength = words.reduce((sum, word) => sum + word.length, 0);
const avgWordLength = totalWordLength / words.length;
const wpm = cpm / avgWordLength;
if (wpm > 300) { // Abitrary value, change as needed, if cpm is greater they are most likely using an automation program
return 0; // Simply give them no score
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review, but I'm happy to move forward with this, but could you just change the calculation to wpm=cpm/5 instead as this is the commonly used wpm/cpm conversion

return Math.floor(cpm);
}

Expand Down