Math.minmax

Michael Rosefield rosyatrandom at gmail.com
Mon Oct 2 16:06:31 UTC 2017


Ah yes, woods, I was looking at the trees.

Still, to carry on with the concise style:

```js
const minMax = (arr=[]) => arr.reduce(
  ([min=Infinity, max=-Infinity], curr) => [ min < curr ? min : curr, max >
curr ? max : curr ], []
)

```

On Mon, 2 Oct 2017 at 16:55 Xavier Stouder <xavier at stouder.io> wrote:

> Same for Michael. Useless to not use a reducer instead of Math.min and
> Math.max if it has worth performance.
>
> Just to be clear, the fact is that your function approximately costs:
> Math.min: one loop over the array
> Math.max: one loop over the array
> Math.minMax: one loop over the array
>
> Math.minMax do in one pass what Math.min and Math.max do in two passes.
> That's the key point.
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20171002/22c76b81/attachment.html>


More information about the es-discuss mailing list