On Mon, Oct 2, 2017 at 8:49 AM, Xavier Stouder <[email protected]> wrote:

> No problem Boris, I edited this times a long time ago.
>
> Naveen, you missed he point. In fact, I just added your code the
> benchmark (link aboce) and it has catastrophic performances.
>

Ya, that's a lot of array creations, not to mention the callback in the
reduce()...

```js
const minMax = (arr=[]) => { let result=[Infinity, -Infinity]; for( let
i=0;i < arr.length;i++ ) {
  result[0] = Math.min(arr[i], result[0]);
  result[1] = Math.max(arr[i], result[1]);
 }
 return result;
}
```
although I suspect this will be faster...
```js
const minMax = (arr=[]) => { let result=[Infinity, -Infinity]; for( let
i=0;i < arr.length;i++ ) {
  result[0] = arr[i] < result[0] ? arr[i]:result[0];
  result[1] = arr[i] > result[1]? arr[i]: result[1];
 }
 return result;
}
```



> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to