blob: fd800e704403b40385dd329e7905abd2053d606f (
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
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
73
74
75
76
77
|
const { Boss } = require("./boss");
const { Employee } = require("./employee");
class Company {
constructor(name) {
this.name = name;
this.employees = new Array();
}
getName() {
return this.name;
}
getEmployees() {
return this.employees;
}
getNumberOfEmployees() {
return this.employees.filter((e) => e instanceof Employee).length;
}
getNumberOfBosses() {
return this.employees.filter((e) => e instanceof Boss).length;
}
addEmployee(target) {
if (!(target instanceof Employee)) {
return;
}
this.employees.push(target);
}
promoteEmployee(targetIndex) {
if (this.employees[targetIndex] instanceof Boss) {
this.employees[targetIndex].accreditationLevel++;
console.log(
"Boss " +
this.employees[targetIndex].getName() +
" is promoted, his level of accreditation is now " +
this.employees[targetIndex].getAccreditation(),
);
} else {
this.employees.splice(
targetIndex,
1,
new Boss(this.employees[targetIndex].getName(), 1),
);
console.log(
"Employee " +
this.employees[targetIndex].getName() +
" is promoted to boss post",
);
}
}
fireEmployee(bossIndex, targetIndex) {
if (this.employees[bossIndex].fire(this.employees[targetIndex])) {
if (this.employees[targetIndex] instanceof Boss) {
console.log(
"Boss " +
this.employees[targetIndex].getName() +
" is no longer in " +
this.name +
" company",
);
} else {
console.log(
"Employee " +
this.employees[targetIndex].getName() +
" is no longer in " +
this.name +
" company",
);
}
this.employees.splice(targetIndex, 1);
}
}
}
module.exports = {
Company,
};
|