Repository navigation
Expand file tree
/
Copy pathTracker.js
More file actions
67 lines (62 loc) · 2.06 KB
/
Copy pathTracker.js
File metadata and controls
67 lines (62 loc) · 2.06 KB
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
const tokens = new Set([
'true', 'false', '||', '&&', '!',
'for', '<', '<=', '>', '>=',
'+=', '-=', '++', '--', '%',
'+', '-', '*', '/', '**',
'length', 'new', '1D index', '2D index', 'pop',
'push', 'if', 'else', 'switch', 'while',
'do-while', 'function'
]);
class Tracker {
constructor() {
this.trackAll = {};
this.trackIncorrect = {};
for (const token of tokens) {
this.trackAll[token] = 0;
this.trackIncorrect[token] = 0;
}
}
trackQuestion(questionString, countWrong) {
var values = questionString.split(' ');
for (const value of values) {
if (!tokens.has(value))
continue;
this.trackAll[value]++;
if (countWrong == 1)
this.trackIncorrect[value]++;
}
for (const value of values) {
if (value.includes('--')) {
this.trackAll['--']++;
if (countWrong == 1)
this.trackIncorrect['--']++;
}
if (value.includes('++')) {
this.trackAll['++']++;
if (countWrong == 1)
this.trackIncorrect['++']++;
}
if (value.includes('arr[')) {
this.trackAll['1D index']++;
if (countWrong == 1)
this.trackIncorrect['1D index']++;
}
if (value.includes('][')) {
this.trackAll['2D index']++;
if (countWrong == 1)
this.trackIncorrect['2D index']++;
}
if (value.includes('if')) {
this.trackAll['if']++;
if (countWrong == 1)
this.trackIncorrect['if']++;
}
if (value.includes('function')) {
this.trackAll['function']++;
if (countWrong == 1)
this.trackIncorrect['function']++;
}
}
}
}
module.exports = Tracker;