blob: e840ffd16bfcfa817f99cf170f40878521176f6f (
plain)
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
|
import type { Student } from "./student-common.ts";
/**
* Class to represent a Group of Students.
*/
class Group {
name: string;
students: Array<Student> = [];
constructor(name: string, students?: Array<Student>) {
this.name = name;
if (typeof students !== "undefined") {
this.students = students;
}
}
setStudents(students: Array<Student>) {
this.students = students;
}
addStudent(student: Student) {
this.students.push(student);
}
async getStudents() {
return this.students;
}
}
const groups = new Map();
function buildGroups(students: Array<Student>) {
for (const student of students) {
let group = groups.get(student.group);
if (!group) {
group = new Group(student.group);
groups.set(student.group, group);
}
group.addStudent(student);
}
}
export { Group, buildGroups, groups as _groups };
|