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, };