From 413501fde6bac909f31ad399781626caa16c8d04 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 12 Jul 2023 00:31:12 +0200 Subject: implement parser breaks --- util/number.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'util') diff --git a/util/number.ts b/util/number.ts index c28864f..98b7e50 100644 --- a/util/number.ts +++ b/util/number.ts @@ -9,3 +9,15 @@ Number.prototype.toChar = function() { return String.fromCharCode(this as number); } +/** @summary get minimum of valid numbers, returns NaN when no valid values are entered */ +export function min(...values: Array) { + values.push(NaN); // make sure .reduce doesn't crash + return (values.filter(v => typeof v === "number") as Array)!.reduce((acc, v) => acc = v < acc ? v : acc); +} + +/** @summary get maximum of valid numbers, returns NaN when no valid values are entered */ +export function max(...values: Array) { + values.push(NaN); // make sure .reduce doesn't crash + return (values.filter(v => typeof v === "number") as Array)!.reduce((acc, v) => acc = v > acc ? v : acc); +} + -- cgit v1.2.3