Skip to content

Commit c091bef

Browse files
committed
Cleaning up
1 parent c3bfe6d commit c091bef

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

game.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -588,21 +588,20 @@
588588
const byDiff = {};
589589
for (const block of blocks) {
590590
const lines = block.trim().split('\n').map(l => l.trim()).filter(Boolean);
591-
const headerMatch = lines[0].match(/^(\d+)\s*,\s*(\d+)\s*:\s*(.+)$/);
592-
const type = +headerMatch[1];
593-
const difficulty = +headerMatch[2];
594-
const question = headerMatch[3].trim();
591+
const header = lines[0].match(/^(\d+)\s*,\s*(\d+)\s*:\s*(.+)$/);
592+
const type = +header[1];
593+
const difficulty = +header[2];
594+
const question = header[3].trim();
595595
const choices = {};
596596
let correct = null;
597597
for (let i = 1; i < lines.length; i++) {
598-
const match = lines[i].match(/^([a-cA-C])\s*:\s*(.+)$/);
599-
const key = match[1].toUpperCase();
600-
choices[key] = match[2].trim();
601-
if (match[1] === match[1].toUpperCase()) correct = key;
598+
const m = lines[i].match(/^([a-cA-C])\s*:\s*(.+)$/);
599+
const key = m[1].toUpperCase();
600+
choices[key] = m[2].trim();
601+
if (m[1] === m[1].toUpperCase()) correct = key;
602602
}
603-
const timeLimit = 5000 + difficulty * 5000;
604-
if (!byDiff[difficulty]) byDiff[difficulty] = [];
605-
byDiff[difficulty].push({ type, difficulty, question, choices, correct, timeLimit });
603+
byDiff[difficulty] ??= [];
604+
byDiff[difficulty].push({ type, difficulty, question, choices, correct, timeLimit: 5000 + difficulty * 5000 });
606605
}
607606
const result = [];
608607
const diffs = Object.keys(byDiff).map(Number).sort((a, b) => a - b);
@@ -612,8 +611,7 @@
612611
const j = Math.floor(Math.random() * (i + 1));
613612
[problems[i], problems[j]] = [problems[j], problems[i]];
614613
}
615-
problems = problems.slice(0, 5);
616-
result.push(...problems);
614+
result.push(...problems.slice(0, 5));
617615
}
618616
return result;
619617
}
@@ -1223,9 +1221,6 @@
12231221
}
12241222
renderMathProblem(p);
12251223
startMathTimer();
1226-
// remove later
1227-
console.log('difficulty:', p.difficulty)
1228-
console.log('correct:', p.correct);
12291224
}
12301225
function renderMathProblem(p) {
12311226
if (p.type === 1) mathTypeEl.textContent = 'Simplify the polynomial';

0 commit comments

Comments
 (0)