diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-07-12 00:31:12 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-07-12 00:31:12 +0200 |
commit | 413501fde6bac909f31ad399781626caa16c8d04 (patch) | |
tree | 7514b0f551a7c41f618d58a50fa56972e6b06170 /util | |
parent | e99ae80f7adc0f0e677381c3cc1549235d3877ab (diff) |
implement parser breaks
Diffstat (limited to 'util')
-rw-r--r-- | util/number.ts | 12 |
1 files changed, 12 insertions, 0 deletions
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<number | null | undefined>) { + values.push(NaN); // make sure .reduce doesn't crash + return (values.filter(v => typeof v === "number") as Array<number>)!.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<number | null | undefined>) { + values.push(NaN); // make sure .reduce doesn't crash + return (values.filter(v => typeof v === "number") as Array<number>)!.reduce((acc, v) => acc = v > acc ? v : acc); +} + |