리팩토링: 코드 최적화
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user