X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=max.mjs;h=2708eb0f51cbfb77bd43a10fde5667bea79e0ac6;hb=72c5f5def8ebcfa65383bed6060157f1e7a5b976;hp=8f1f698a6a8b5f11488444913b70e17b4c11005d;hpb=48f5216deed3bc4d9a64e81822fe8d6bd5c5cdcd;p=benchmarks-js.git diff --git a/max.mjs b/max.mjs index 8f1f698..2708eb0 100644 --- a/max.mjs +++ b/max.mjs @@ -1,4 +1,5 @@ import Benchmark from 'benny' + import { generateRandomNumberArray } from './benchmark-utils.mjs' const size = 10000 @@ -10,11 +11,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 +24,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 +36,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 +70,4 @@ 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) => { - console.error(err) -}) +).catch(console.error)