-
Notifications
You must be signed in to change notification settings - Fork 1
/
phonetic.ts
80 lines (73 loc) · 1.71 KB
/
phonetic.ts
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const readline = require('readline');
// According to ITU "Phonetic alphabet and figure code"
const dict: {[key in string]: string} = {
A: "Alfa",
B: "Bravo",
C: "Charlie",
D: "Delta",
E: "Echo",
F: "Foxtrot",
G: "Golf",
H: "Hotel",
I: "India",
J: "Juliett",
K: "Kilo",
L: "Lima",
M: "Mike",
N: "November",
O: "Oscar",
P: "Papa",
Q: "Quebec",
R: "Romeo",
S: "Sierra",
T: "Tango",
U: "Uniform",
V: "Victor",
W: "Whiskey",
X: "X-ray",
Y: "Yankee",
Z: "Zulu",
0: "Nadazero",
1: "Unaone",
2: "Bissotwo",
3: "Terrathree",
4: "Kartefour",
5: "Pantafive",
6: "Soxisix",
7: "Setteseven",
8: "Oktoeight",
9: "Novenine",
".-decimal": "Decimal",
".-stop": "Stop",
}
function randomCharacter(): string {
const code = "A".charCodeAt(0) + Math.floor(Math.random() * 26);
return String.fromCharCode(code);
}
function test() {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const word = Array.from(Array(5)).map(() => randomCharacter()).join('')
const correct = word.split("").map(c => dict[c]).join(" ")
const t0 = Date.now();
rl.question(word + '\n', (answer: string) => {
const tEnd = Date.now();
const answerUpper = answer.toUpperCase();
const correctUpper = correct.toUpperCase();
if (correctUpper === answerUpper) {
console.info(`Correct in ${tEnd - t0}ms`);
}
else {
console.warn("Wrong!");
console.info("CORRECT:", correctUpper);
}
rl.close();
test();
});
}
function main() {
test();
}
main()