+ 1
JS convert milliseconds to wpm (typing speed)
JS convert millisecond delays to WPM So the goal in this is to ... user enters x WPM, and a text / string is typed with that speed (wpm). WPM = words per minute (typing speed) I have my own calculation, you’ll see it in the code The problem is: above 100WPM, it doesn’t seem to be working (the wpm you enter looks a lot slower than what it should). So, I’m wondering if you guys have a formula for this, or if you think I need to change something in my calculation. (Explained more in the code) ...
7 ответов
+ 3
In this line
(100 * 5) / speed / (100 / 2.2);
Change it to a constant dividing speed.
Also, a time interval too small, such as 2ms, is invalid, because the calculation in each frame takes up time.
+ 2
means don't do unnecessary calculation in each iteration.
you should calculate 100 * 5 / 100 * 2.2 manually first, and then in your code you divide this calculated result by speed.
+ 1
+ 1
Gordon what is constant dividing speed?
like ... 2 instead of 2.2?
+ 1
that new approach takes up even more time...
You should do less calculations in each frame, like this:
let wpm = 100;
let interval = 600000 / word;
interval doesn't work for interval lower than 10.
Check my demo code in this thread :
https://www.sololearn.com/Discuss/1690442/?ref=app
it is unavoidable, because of the time needed to process the operations in each frame.
+ 1
Gordon ahh i see.
Let’s do the calculation without the ...interval()
In this ... formula
// 0.0001 = about 1000 (or more) wpm
// 0.01 = about 500 wpm
// 0.1 = about 100 wpm
// 1 = about 10 wpm
// 11 = about 1 wpm (minimum)
https://code.sololearn.com/WOZ0TZq5XLec/?ref=app
I can probably fix the interval later if I can get the calculation right.
var inDelay = speed / (speed * (0.01 * speed)) / (0.1 * speed
the 0.01 is 1* of the speed.
And 0.1 is 10% of the speed.
0
@Gordon
Let's try a different calculation:
// 0.0001 = about 1000 (or more) wpm
// 0.001 = about 900
// 0.01 = about 500 wpm
// 0.1 = about 100 wpm
// 1 = about 10 wpm
// 11 = about 1 wpm (minimum)
This is the new calculation I came up with, and it kinda...works for the bigger numbers, not for the smaller numbers like.. 1, 2, 3..
This is the new calculation:
var inDelay = speed / (speed * (0.01 * speed)) / (0.1 * speed)
https://code.sololearn.com/WWYcxxXWZZlA/#js
And this is the original (just in case we need to use this one instead of the new one)
https://code.sololearn.com/WOZ0TZq5XLec/?ref=app#js