This repository has been archived by the owner on Feb 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuestionPaper.js
61 lines (52 loc) · 1.47 KB
/
QuestionPaper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class QuestionPaper {
constructor(totalMarks, questionList, difficulty) {
this.totalMarks = totalMarks;
this.questionList = questionList;
this.difficulty = difficulty;
this.selectedQuestions = { easy: [], medium: [], hard: [] };
}
check() {
if (
this.totalMarks !==
(this.difficulty.easy + this.difficulty.medium, this.difficulty.hard)
) {
console.info("Total marks doesn't match with given difficulty values");
}
}
make() {
const marksToBeAdded = {
Easy: this.totalMarks * (this.difficulty.easy / 100),
Medium: this.totalMarks * (this.difficulty.medium / 100),
Hard: this.totalMarks * (this.difficulty.hard / 100),
};
const question = 0;
const difficulty = 3;
const marks = 4;
for (let data of this.questionList) {
switch (data[difficulty]) {
case "Easy":
if (marksToBeAdded["Easy"] === 0) continue;
this.selectedQuestions.easy.push(data);
marksToBeAdded["Easy"] -= data[marks];
break;
case "Medium":
if (marksToBeAdded["Medium"] === 0) continue;
this.selectedQuestions.medium.push(data);
marksToBeAdded["Medium"] -= data[marks];
break;
case "Hard":
if (marksToBeAdded["Hard"] === 0) continue;
this.selectedQuestions.hard.push(data);
marksToBeAdded["Hard"] -= data[marks];
break;
default:
console.info(`Unknown difficulty on ${data[question]}`);
break;
}
}
}
print() {
console.info(this.selectedQuestions);
}
}
module.exports = QuestionPaper;