리팩토링: 코드 최적화

This commit is contained in:
2026-05-25 18:42:13 +09:00
parent 5ee33bf0d3
commit d56cada1ec
11 changed files with 215 additions and 175 deletions
+9 -2
View File
@@ -25,7 +25,12 @@ function formatLatexTermPair(first: number, second: number) {
return `${first} ${operator} ${Math.abs(second)}`;
}
function createProblem({ multiplier, a, operator, b }: ProblemSeed) {
function createProblem({
multiplier,
a,
operator,
b,
}: ProblemSeed): ParenthesisSignProblem {
const distributedA = multiplier * a;
const distributedB = operator === "-" ? multiplier * -b : multiplier * b;
const key = `${multiplier}:${a}:${operator}:${b}`;
@@ -65,6 +70,8 @@ function createAllProblemSeeds() {
return seeds;
}
const ALL_PROBLEM_SEEDS = createAllProblemSeeds();
function shuffle<T>(items: T[]) {
const shuffled = [...items];
@@ -103,7 +110,7 @@ export function generateSession(count = 10): ParenthesisSignProblem[] {
throw new Error(`count cannot exceed ${MAX_PROBLEM_COUNT}.`);
}
return shuffle(createAllProblemSeeds()).slice(0, count).map(createProblem);
return shuffle(ALL_PROBLEM_SEEDS).slice(0, count).map(createProblem);
}
export function gradeAnswer(