리펙토링: 코드 최적화
This commit is contained in:
@@ -6,6 +6,7 @@ import type {
|
||||
VariableUserAnswer,
|
||||
VariableGradeResult,
|
||||
} from "./variable-types";
|
||||
import { formatParenthesisExpressionLatex } from "./parenthesis-latex";
|
||||
|
||||
const MIN_MULTIPLIER = -9;
|
||||
const MAX_MULTIPLIER = -1;
|
||||
@@ -95,10 +96,6 @@ export function formatVariableTermLatex(
|
||||
return `${term.coefficient}x`;
|
||||
}
|
||||
|
||||
function formatParenthesisTermLatex(term: VariableParenthesisTerm) {
|
||||
return formatVariableTermLatex(term);
|
||||
}
|
||||
|
||||
export function formatVariableExpressionLatex(
|
||||
terms: DistributedVariableTerm[],
|
||||
) {
|
||||
@@ -164,8 +161,6 @@ function createChoices(
|
||||
|
||||
function createProblem(seed: VariableProblemSeed): VariableParenthesisProblem {
|
||||
const { multiplier, terms, operators } = seed;
|
||||
const [firstTerm, secondTerm] = terms;
|
||||
const [operator] = operators;
|
||||
const key = [
|
||||
multiplier,
|
||||
...terms.flatMap((term, index) =>
|
||||
@@ -189,18 +184,14 @@ function createProblem(seed: VariableProblemSeed): VariableParenthesisProblem {
|
||||
multiplier,
|
||||
terms,
|
||||
operators,
|
||||
operator,
|
||||
firstTerm,
|
||||
secondTerm,
|
||||
correctTerms,
|
||||
choices,
|
||||
latexBefore: `${multiplier}\\left(${terms
|
||||
.map((term, index) => {
|
||||
if (index === 0) return formatParenthesisTermLatex(term);
|
||||
|
||||
return `${operators[index - 1]} ${formatParenthesisTermLatex(term)}`;
|
||||
})
|
||||
.join(" ")}\\right)`,
|
||||
latexBefore: formatParenthesisExpressionLatex({
|
||||
multiplier,
|
||||
terms,
|
||||
operators,
|
||||
formatTermLatex: formatVariableTermLatex,
|
||||
}),
|
||||
latexAfter: formatVariableExpressionLatex(correctTerms),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user