mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-30 03:23:48 +01:00
refector of setEmployeeToJob
This commit is contained in:
parent
3e36e6a80b
commit
da955a4774
@ -174,34 +174,16 @@ export class OfficeSpace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setEmployeeToJob(job: string, amount: number): boolean {
|
setEmployeeToJob(job: string, amount: number): boolean {
|
||||||
let unassignedCount = 0;
|
let jobCount = this.employees.reduce((acc, employee) => (employee.pos === job ? acc + 1 : acc), 0);
|
||||||
let jobCount = 0;
|
|
||||||
for (let i = 0; i < this.employees.length; ++i) {
|
|
||||||
if (this.employees[i].pos === EmployeePositions.Unassigned) {
|
|
||||||
unassignedCount++;
|
|
||||||
} else if (this.employees[i].pos === job) {
|
|
||||||
jobCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (jobCount == amount) return false;
|
for (const employee of this.employees) {
|
||||||
if ((jobCount + unassignedCount) < amount) return false;
|
if (jobCount == amount) return true
|
||||||
|
if (employee.pos === EmployeePositions.Unassigned && jobCount <= amount) {
|
||||||
for (let i = 0; i < this.employees.length; ++i) {
|
employee.pos = job;
|
||||||
if (this.employees[i].pos === EmployeePositions.Unassigned) {
|
|
||||||
if (jobCount <= amount) {
|
|
||||||
this.employees[i].pos = job;
|
|
||||||
jobCount++;
|
jobCount++;
|
||||||
unassignedCount--;
|
} else if (employee.pos === job && jobCount >= amount) {
|
||||||
}
|
employee.pos = EmployeePositions.Unassigned;
|
||||||
if (jobCount === amount) break;
|
|
||||||
} else if (this.employees[i].pos === job) {
|
|
||||||
if (jobCount >= amount) {
|
|
||||||
this.employees[i].pos = EmployeePositions.Unassigned;
|
|
||||||
jobCount--;
|
jobCount--;
|
||||||
unassignedCount++;
|
|
||||||
}
|
|
||||||
if (jobCount === amount) break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (jobCount !== amount) return false;
|
if (jobCount !== amount) return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user