Refactor reactor class to improve NaN handling and add utility function for NaN assertions

This commit is contained in:
2025-07-04 16:28:35 +02:00
parent 6755f2bd28
commit a2cfb20e2c
2 changed files with 48 additions and 41 deletions

18
src/utils.js Normal file
View File

@@ -0,0 +1,18 @@
/**
* Assert that no NaN values are present in an array.
* @param {Array} arr
* @param {string} label
*/
function assertNoNaN(arr, label = "array") {
if (Array.isArray(arr)) {
for (const el of arr) {
assertNoNaN(el, label);
}
} else {
if (Number.isNaN(arr)) {
throw new Error(`NaN detected in ${label}!`);
}
}
}
module.exports = { assertNoNaN };