Skip to content

Commit 05a4913

Browse files
fix the safeSubtract
1 parent c4cc2b0 commit 05a4913

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

modules/util/MathUtil.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,7 @@ export class RunningAverage {
105105
* @returns {number} - x - y or 0 if x or is not a number.
106106
*/
107107
export function safeSubtract(x:unknown, y:unknown):number {
108-
return typeof x === 'number' && typeof y === 'number' ? x - y : 0;
108+
const numX = Number(x);
109+
const numY = Number(y);
110+
return !Number.isNaN(x) && !Number.isNaN(y) ? numX - numY : 0;
109111
}

0 commit comments

Comments
 (0)