X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=max.mjs;h=60fcdeac0764ba2016cd71050b94e27f228499f3;hb=0b694507b40b04ff7b905c0d3cade8d72ddc7cc9;hp=8f1f698a6a8b5f11488444913b70e17b4c11005d;hpb=48f5216deed3bc4d9a64e81822fe8d6bd5c5cdcd;p=benchmarks-js.git diff --git a/max.mjs b/max.mjs index 8f1f698..60fcdea 100644 --- a/max.mjs +++ b/max.mjs @@ -10,11 +10,11 @@ const testArray = generateRandomNumberArray(size) * @returns */ function loopMax (values) { - let max = -Infinity + let maximum = -Infinity for (const value of values) { - if (value > max) max = value + if (value > maximum) maximum = value } - return max + return maximum } /** @@ -23,7 +23,10 @@ function loopMax (values) { * @returns */ function reduceTernaryMax (values) { - return values.reduce((a, b) => (a > b ? a : b), -Infinity) + return values.reduce( + (maximum, num) => (maximum > num ? maximum : num), + -Infinity + ) } /** @@ -32,7 +35,7 @@ function reduceTernaryMax (values) { * @returns */ function reduceMathMax (values) { - return values.reduce((a, b) => Math.max(a, b), -Infinity) + return values.reduce((maximum, num) => Math.max(maximum, num), -Infinity) } /** @@ -66,6 +69,6 @@ Benchmark.suite( Benchmark.save({ file: 'max', format: 'json', details: true }), Benchmark.save({ file: 'max', format: 'chart.html', details: true }), Benchmark.save({ file: 'max', format: 'table.html', details: true }) -).catch((err) => { +).catch(err => { console.error(err) })