UNPKG

@sunzhongmou/math

Version:
63 lines 2.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Exercise = exports.QuestionType = void 0; const uuid_1 = require("uuid"); var QuestionType; (function (QuestionType) { QuestionType[QuestionType["RAW"] = 0] = "RAW"; QuestionType[QuestionType["FILL"] = 1] = "FILL"; })(QuestionType = exports.QuestionType || (exports.QuestionType = {})); class Exercise { constructor(rawQuestion, fillQuestion) { this.id = uuid_1.v4(); this.rawQuestions = rawQuestion; this.fillQuestions = fillQuestion; } sameIdentityAs(other) { return this.id === other.id; } addQuestion(question, type) { switch (type) { case QuestionType.FILL: this.fillQuestions.push(question); break; case QuestionType.RAW: this.rawQuestions.push(question); break; default: this.rawQuestions.push(question); } } generateRawQuestions() { const questionList = []; for (const exp of this.rawQuestions) { questionList.push(exp.getRaw()); } return questionList; } generateFillQuestions() { const questionList = []; for (const exp of this.fillQuestions) { let rawQuestion = exp.getRaw(); const hiddenOperand = Math.random() >= 0.5; if (hiddenOperand) { rawQuestion = rawQuestion.replace(`${exp.operationSets[0].operand}`, //TODO: need refactor '__'); } else { rawQuestion = rawQuestion.replace(`${exp.destinationOperand}`, '__'); } rawQuestion = rawQuestion.replace('=', `= ${exp.execute()}`); questionList.push(rawQuestion); } return questionList; } generate() { let questionList = []; questionList = questionList.concat(this.generateRawQuestions()); questionList = questionList.concat(this.generateFillQuestions()); return questionList; } } exports.Exercise = Exercise; //# sourceMappingURL=exercise.js.map