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
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
}
return Math.floor(cpm);
}

Expand Down