添加字典表解析
This commit is contained in:
34
shared/pubUtils/dictionary/DicQuestion.ts
Normal file
34
shared/pubUtils/dictionary/DicQuestion.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
// 奇遇题库
|
||||
import {readJsonFile} from '../util'
|
||||
import { FILENAME } from '../../consts/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;
|
||||
}
|
||||
Reference in New Issue
Block a user