From e7150b7e2d0d6d6c38b9d6f5b6572fd001035494 Mon Sep 17 00:00:00 2001
From: Blank_Alt <12406-Blank_Alt@users.noreply.gitgud.io>
Date: Fri, 21 Aug 2020 22:53:37 -0700
Subject: [PATCH] Update between function

---
 devNotes/Useful JS Function Documentation.txt | 6 ++++--
 js/utils.js                                   | 9 +++++++--
 src/js/slaveCostJS.js                         | 2 +-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/devNotes/Useful JS Function Documentation.txt b/devNotes/Useful JS Function Documentation.txt
index dc49283b8ec..25502b5fa51 100644
--- a/devNotes/Useful JS Function Documentation.txt	
+++ b/devNotes/Useful JS Function Documentation.txt	
@@ -225,8 +225,10 @@ UtilJS [script]
 
 	weightedArray2HashMap()
 
-	between(a, low, high) - outputs the value down the middle of two inputs e.g.
-		between($trees, 1, 3) returns $trees = 2
+	between(a, low, high, mode = 'exclusive') - checks if the value is between low and high inputs. mode: defaults to exclusive but also supports 'inclusive'. e.g.
+		$trees === 1.
+		exclusive - between($trees, 1, 3) -> false
+		inclusive - between($trees, 1, 3) -> true
 
 	def() - Returns whether the input is defined, similar to SugarCube's def.
 
diff --git a/js/utils.js b/js/utils.js
index 2026efe2e9c..112b768fdca 100644
--- a/js/utils.js
+++ b/js/utils.js
@@ -28,12 +28,17 @@ function isFloat(n) {
  * @param {number} a
  * @param {number} low
  * @param {number} high
+ * @param {string} mode, deafults to 'exclusive' but also supports 'inclusive'.
  * @returns {boolean}
  */
-function between(a, low, high) {
+function between(a, low, high, mode = 'exclusive') {
 	if (low === null) { low = -Infinity; }
 	if (high === null) { high = Infinity; }
-	return (a > low && a < high);
+	if (mode === 'exclusive') {
+		return a > low && a < high;
+	} else if (mode === 'inclusive') {
+		return a >= low && a <= high;
+	}
 }
 
 /**
diff --git a/src/js/slaveCostJS.js b/src/js/slaveCostJS.js
index 8f805e46b4d..fbfc900bf5e 100644
--- a/src/js/slaveCostJS.js
+++ b/src/js/slaveCostJS.js
@@ -415,7 +415,7 @@ globalThis.BeautyArray = (function() {
 				adjustBeauty("Age: Youth Preferentialist", ((30 - slave.visualAge) / (30 - V.minimumSlaveAge) * ((arcology.FSYouthPreferentialist / 2) + (arcology.FSYouthPreferentialistLaw * 10)))); /* max 60 */
 			}
 		} else if (arcology.FSMaturityPreferentialist !== "unset") {
-			if (between(V.retirementAge, 30, 60)) {
+			if (between(V.retirementAge, 30, 60, 'inclusive')) {
 				adjustBeauty("Age: Maturity Preferentialist", ((30 - slave.visualAge) / (30 - V.retirementAge) * ((arcology.FSMaturityPreferentialist / 2) + (arcology.FSMaturityPreferentialistLaw * 10)))); /* max 60, problems if retirementAge is 30 or under */
 			}
 		}
-- 
GitLab