From: Jérôme Benoit Date: Tue, 21 May 2024 17:57:26 +0000 (+0200) Subject: refactor: code cleanups X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=ae56b43d49a0cb5a88a953a7f6ef42f02e4a12d9;p=benchmarks-js.git refactor: code cleanups Signed-off-by: Jérôme Benoit --- diff --git a/benchmark-utils.mjs b/benchmark-utils.mjs index d0d5a62..8e32f90 100644 --- a/benchmark-utils.mjs +++ b/benchmark-utils.mjs @@ -26,7 +26,7 @@ export function generateRandomFloat (max = Number.MAX_VALUE, min = 0) { if (max < min) { throw new RangeError('Invalid interval') } - if (max - min === Infinity) { + if (max - min === Number.POSITIVE_INFINITY) { throw new RangeError('Invalid interval') } return (randomBytes(4).readUInt32LE() / 0xffffffff) * (max - min) + min diff --git a/max.mjs b/max.mjs index 23fcfdf..8675f82 100644 --- a/max.mjs +++ b/max.mjs @@ -11,7 +11,7 @@ const testArray = generateRandomNumberArray(size) * @returns */ function loopMax (values) { - let maximum = -Infinity + let maximum = Number.NEGATIVE_INFINITY for (const value of values) { if (value > maximum) maximum = value } @@ -26,7 +26,7 @@ function loopMax (values) { function reduceTernaryMax (values) { return values.reduce( (maximum, num) => (maximum > num ? maximum : num), - -Infinity + Number.NEGATIVE_INFINITY ) } @@ -36,7 +36,10 @@ function reduceTernaryMax (values) { * @returns */ function reduceMathMax (values) { - return values.reduce((maximum, num) => Math.max(maximum, num), -Infinity) + return values.reduce( + (maximum, num) => Math.max(maximum, num), + Number.NEGATIVE_INFINITY + ) } /** diff --git a/min.mjs b/min.mjs index 858b1eb..51ce4ce 100644 --- a/min.mjs +++ b/min.mjs @@ -11,7 +11,7 @@ const testArray = generateRandomNumberArray(size) * @returns */ function loopMin (values) { - let minimum = Infinity + let minimum = Number.POSITIVE_INFINITY for (const value of values) { if (value < minimum) minimum = value } @@ -26,7 +26,7 @@ function loopMin (values) { function reduceTernaryMin (values) { return values.reduce( (minimum, num) => (minimum < num ? minimum : num), - Infinity + Number.POSITIVE_INFINITY ) } @@ -36,7 +36,10 @@ function reduceTernaryMin (values) { * @returns */ function reduceMathMin (values) { - return values.reduce((minimum, num) => Math.min(minimum, num), Infinity) + return values.reduce( + (minimum, num) => Math.min(minimum, num), + Number.POSITIVE_INFINITY + ) } /** diff --git a/quick-select.mjs b/quick-select.mjs index 49dc705..8f588f2 100644 --- a/quick-select.mjs +++ b/quick-select.mjs @@ -27,7 +27,7 @@ const tasksMap = generateRandomTasksMap(60, 20) */ function loopSelect (tasksMap) { let minKey - let minValue = Infinity + let minValue = Number.POSITIVE_INFINITY for (const [key, value] of tasksMap) { if (value === 0) { return key