|
@@ -25,7 +25,7 @@ export function loadInput(dayNumber, parsingFunction, literalPath = false) {
|
|
* @returns {-1|0|1}
|
|
* @returns {-1|0|1}
|
|
*/
|
|
*/
|
|
export function numericAscSort(a, b) {
|
|
export function numericAscSort(a, b) {
|
|
- return a - b;
|
|
|
|
|
|
+ return clamp(a - b);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -39,4 +39,17 @@ export function numericAscSort(a, b) {
|
|
*/
|
|
*/
|
|
export function strToInt(string) {
|
|
export function strToInt(string) {
|
|
return parseInt(string, 10);
|
|
return parseInt(string, 10);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Clamp a number between two other numbers
|
|
|
|
+ *
|
|
|
|
+ * @param {number} value The value to be clamped
|
|
|
|
+ * @param {number} min The minimum value
|
|
|
|
+ * @param {number} max The maximum value
|
|
|
|
+ *
|
|
|
|
+ * @returns {number} The clamped value
|
|
|
|
+ */
|
|
|
|
+export function clamp(value, min = -1, max = 1) {
|
|
|
|
+ return Math.max(min, Math.min(max, value));
|
|
}
|
|
}
|