-
Notifications
You must be signed in to change notification settings - Fork 0
/
transcript.js
72 lines (55 loc) · 1.6 KB
/
transcript.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
62
63
64
65
66
67
68
69
70
71
72
'use strict';
const dayjs = require('dayjs');
function Exam(code, name, credits, date, score, laude=false) {
this.code = code;
this.name = name;
this.credits = credits;
this.score = score;
this.laude = laude;
this.date = date;
this.toString = () => (`${this.code} - ${this.name} = ${this.score} (${this.date})`);
}
function ExamList() {
this.list = [];
this.add = (e) => {
this.list.push(e);
};
this.find = (code) => {
for (const c of this.list)
if(c.code === code)
return c;
return undefined;
};
this.afterDate = (date) => {
return this.list.filter(course => course.date.isAfter(date));
};
this.listByDate = () => {
return [...this.list].sort((a,b) => (a.date.isAfter(b.date) ? 1 : -1));
};
this.listByScore = () => {
return [...this.list].sort((a,b) => (b.score - a.score));
};
this.average = () => {
let avg = 0;
for (const c of this.list)
avg += c.score;
avg /= this.list.length;
return avg;
};
}
const sdp = new Exam('02XXX', 'System and Device Programming', 10, dayjs('2021-07-01'), 21);
const wa1 = new Exam('01KTF', 'Web Applications I', 6, dayjs('2021-06-01'), 30, true);
const exams = new ExamList();
exams.add(wa1);
exams.add(sdp);
console.log("FIND");
console.log(`${exams.find('01KTF')}`);
console.log(`${exams.find('031KTF')}`);
console.log("AFTER DATE");
console.log(exams.afterDate(dayjs('2021-06-15')).toString());
console.log("BY DATE");
console.log(exams.listByDate().toString());
console.log("BY SCORE");
console.log(exams.listByScore().toString());
console.log("AVERAGE");
console.log(exams.average());