-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.js
48 lines (46 loc) · 1.5 KB
/
file.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
function prerequisitiesValidator (Prerequisities, Enrollment){
// arg Prerequisities should be in this format:
// Prerequisities = {"code":{"1": ["COMP9021", "COMP9024"],"2": ["COMP9020", "COMP9024"]},"UOC": 0}
let canBeEnrolled = false;
//console.log(Prerequisities.code, Enrollment);
if (Prerequisities.code[1].length === 0 && Prerequisities.code[2].length === 0){
//console.log('1');
canBeEnrolled = true;
}else if(Prerequisities.code[1].length >= 1 && Prerequisities.code[2].length === 0){
//console.log('2');
for(let course of Prerequisities.code[1]){
if(Enrollment.includes(course)){
canBeEnrolled = true;
break;
}
}
}else if(Prerequisities.code[1].length === 0 && Prerequisities.code[2] >= 1){
//console.log('3');
for(let course of Prerequisities.code[2]){
if(Enrollment.includes(course)){
canBeEnrolled = true;
break;
}
}
}else if(Prerequisities.code[1].length >= 1 && Prerequisities.code[2].length >=1 ){
//console.log('4');
let validatorCodeList1 = false;
let validatorCodeList2 = false;
for(let course of Prerequisities.code[1]){
if(Enrollment.includes(course)){
canBeEnrolled = true;
break;
}
}
for(let course of Prerequisities.code[2]){
if(Enrollment.includes(course)){
canBeEnrolled = true;
break;
}
}
if(validatorCodeList1 === true && validatorCodeList2 === true){
canBeEnrolled = true;
}
}
return canBeEnrolled;
}