Skip to content
Snippets Groups Projects
Commit 1a961a9e authored by brickode's avatar brickode
Browse files

Refactored median nanny intelligence out of main for loop

parent 813aef74
No related branches found
No related tags found
1 merge request!7243Children Report Rework
......@@ -9,10 +9,10 @@ App.Facilities.Nursery.childrenReport = function childrenReport() {
Matron = V.Matron,
nannies = App.Utils.sortedEmployees(App.Entity.facilities.nursery),
NL = App.Entity.facilities.nursery.employeesIDs().size,
CL = V.cribs.length;
CL = V.cribs.length,
let
r = [];
medianNannyIntelligence = NL ? findMedianNannyIntelligence() : null,
medianNannyIntelligenceImplant = NL ? findMedianNannyIntelligenceImplant() : null;
for (const child of V.cribs) {
const childDiv = App.UI.DOM.appendNewElement("div", frag);
......@@ -132,39 +132,23 @@ App.Facilities.Nursery.childrenReport = function childrenReport() {
function nannyEducationEffects(child) {
// TODO: expand this
const
intelligenceValues = [],
intelligenceImplantValues = [],
firstNanny = nannies[0],
theNanniesAre = NL > 1 ? `The nannies are mostly` : `${firstNanny.slaveName} is`,
theChildren = CL > 1 ? `the children` : child.slaveName;
let
medianIntelligence = 0,
medianIntelligenceImplant = 0;
for (const nanny of nannies) {
intelligenceValues.push(nanny.intelligence);
intelligenceImplantValues.push(nanny.intelligenceImplant);
}
medianIntelligence = median(intelligenceValues);
medianIntelligenceImplant = median(intelligenceImplantValues);
if (medianIntelligence + medianIntelligenceImplant > 65) {
if (medianNannyIntelligence + medianNannyIntelligenceImplant > 65) {
child.intelligenceImplant += 3;
return `${theNanniesAre} very intelligent and well educated and are able to teach ${theChildren} very effectively. `;
} else if (medianIntelligence > 50) {
} else if (medianNannyIntelligence > 50) {
child.intelligenceImplant += 2;
return `${theNanniesAre} very intelligent and able to teach ${theChildren} quite effectively. `;
} else if (medianIntelligenceImplant > 25) {
} else if (medianNannyIntelligenceImplant > 25) {
child.intelligenceImplant += 2;
return `${theNanniesAre} very well educated and able to teach ${theChildren} quite effectively. `;
} else if (medianIntelligenceImplant > 15) {
} else if (medianNannyIntelligenceImplant > 15) {
child.intelligenceImplant++;
return `${theNanniesAre} well educated and able to teach ${theChildren} fairly effectively. `;
......@@ -364,8 +348,26 @@ App.Facilities.Nursery.childrenReport = function childrenReport() {
}
}
}
}
return r.join(' ');
function findMedianNannyIntelligence() {
const intelligenceValues = [];
for (const nanny of nannies) {
intelligenceValues.push(nanny.intelligence);
}
return median(intelligenceValues);
}
function findMedianNannyIntelligenceImplant() {
const intelligenceImplantValues = [];
for (const nanny of nannies) {
intelligenceImplantValues.push(nanny.intelligenceImplant);
}
return median(intelligenceImplantValues);
}
return frag;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment