-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate_cpm.js
32 lines (26 loc) · 1 KB
/
calculate_cpm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*You are given 2 inputs:
- A string, text, of alpha-numeric and/or symbolic characters.
- And an integer, time, representing a duration in seconds.
You must output the CPM of the text, rounded to 1 decimal place (1 d.p).
(P.S. CPM stands for Characters Per Minute.)
You might like to check out this link:
https://chatableapps.com/technology/understanding-cpm-in-typing-a-comprehensive-guide-for-beginners/
Entrée
Line 1: A string, text, of alpha-numeric and/or symbolic characters.
Line 2: An integer, time, representing a duration in seconds.
Sortie
Line 1: The answer, CPM, as a string formatted as "CPM cpm".
Contraintes
0 < (length of text) <= 750
0 < time in seconds <= 250
Exemple
Entrée
The quick brown fox jumps over the lazy dog.
60
Sortie
44.0 cpm*/
function calculate_cpm(text, time) {
return (text.length / (time / 60)).toFixed(1);
}
console.log(calculate_cpm("The quick brown fox jumps over the lazy dog.", 60)); // 44.0
console.log(calculate_cpm("Imposible isn't algerian anymore !", 120)); // 17.0