Files
ZYZ/shared/pubUtils/dictionary/DicQuestion.ts
2020-12-16 16:47:29 +08:00

34 lines
798 B
TypeScript

// 奇遇题库
import {readJsonFile} from '../util'
import { FILENAME } from '../../consts'
export interface DicQuestion {
// 题目id
readonly id: number;
// 题干
readonly question: string;
// 答案
readonly answer: Array<string>;
// 正确答案
readonly correct: number;
}
const str = readJsonFile(FILENAME.DIC_QUESTION);
let arr = JSON.parse(str);
export const dicQuestion = new Map<number, DicQuestion>();
arr.forEach(o => {
o.answer = parseAnswer(o.a1, o.a2, o.a3, o.a4)
dicQuestion.set(o.id, o);
});
function parseAnswer(a1: string, a2: string, a3: string, a4: string) {
let answer = new Array<string>();
if(a1) answer.push(a1);
if(a2) answer.push(a2);
if(a3) answer.push(a3);
if(a4) answer.push(a4);
return answer;
}