Math.minmax

Naveen Chawla naveen.chwl at gmail.com
Mon Oct 2 15:34:07 UTC 2017


I would just use reduce for this. Reason: I think any multi var result
format is a little messy. I find it better to let the dev decide on the
result format, e.g.:

```js
const minMax =
     array.reduce(
         (accumulator, currentValue)=>{
              return {
                  min: Math.min(currentValue, accumulator.min),
                  max: Math.max(currentValue, accumulator.max)
              }
         },
         {
             min: Infinity,
             max: -Infinity
         }
     )
```

Good thing is, this can easily be refactored to accept arrays with objects
that contain the values, instead of just an array of numbers, as well as
the ability to calculator other accumulated values (e.g. mean average etc.)
in the same call.

Do let me know if you think I'm missing the point

On Mon, 2 Oct 2017 at 19:16 Boris Zbarsky <bzbarsky at mit.edu> wrote:

> On 10/2/17 7:10 AM, Xavier Stouder wrote:
> > Don't know what Boris mean when he talks about recreation bits
>
> Fwiw, it looks like the code at
> https://esbench.com/bench/595c1b1899634800a03488b9 does not have the
> array recreation bits (function whatever(...args)) that earlier
> benchmarks for this had.
>
> -Boris
> _______________________________________________
> 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/50eab6f6/attachment.html>


More information about the es-discuss mailing list