From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:08:27 +0200 Subject: add: graphs et rushs --- graphs/js/myCompany/company.js | 77 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 graphs/js/myCompany/company.js (limited to 'graphs/js/myCompany/company.js') diff --git a/graphs/js/myCompany/company.js b/graphs/js/myCompany/company.js new file mode 100644 index 0000000..fd800e7 --- /dev/null +++ b/graphs/js/myCompany/company.js @@ -0,0 +1,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, +}; -- cgit v1.2.3