-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquizzzler2.js
More file actions
24 lines (22 loc) · 907 Bytes
/
quizzzler2.js
File metadata and controls
24 lines (22 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const fs = require('file-system');
function renderQuiz() {
let textTorender = fs.readFileSync('./uploads/quiz.txt', 'utf8');
if (textTorender != null || undefined) {
const wholeQuestionPattern = /\d+?\. .+(\r\n(\r\n[a-z||A-Z]\. .+)+)/gm;
const promptPattern = /\d+?\. .+/;
const fOptionPattern = /[a-z||A-Z]\. [^!\n\r]+/g;
const cOptionPattern = /[a-z||A-Z]\. .+!/g;
let wholeQuestion = textTorender.match(wholeQuestionPattern);
const questionJSONed = {};
for (let i = 0; i < wholeQuestion.length; i++) {
let question = [];
question[i] = {};
question[i]["prompt"] = wholeQuestion[i].match(promptPattern);
question[i]["fOptions"] = wholeQuestion[i].match(fOptionPattern);
question[i]["cOption"] = wholeQuestion[i].match(cOptionPattern);
questionJSONed[i] = question[i];
}
return questionJSONed;
}
}
module.exports = renderQuiz;