Spaceship Operator

Isiah Meadows isiahmeadows at gmail.com
Tue Jun 27 20:29:56 UTC 2017


Inline

On Tue, Jun 27, 2017, 16:19 Mike Samuel <mikesamuel at gmail.com> wrote:

> On Tue, Jun 27, 2017 at 4:13 PM, Isiah Meadows <isiahmeadows at gmail.com>
> wrote:
> > For what it's worth, for most practical purposes, `arr.sort((a, b) => b -
> > a))` works well enough. (The only thing it doesn't work well with are
> NaNs,
> > but in practice, those almost never occur.)
>
> Don't numeric comparison operators typically sort -0 before +0?
>

In JavaScript, not if I recall correctly. The only places where signed
zeroes are relevant is in division.


> ((a,b)=>b-a) is also problematic for an array that contains two or
> more infinite values with the same sign and one or more finite values
> since isNaN(Infinity-Infinity).   That NaN from the comparator can be
> triggered or not based on details of the sorting algo and the precise
> placement on the Infinities.
>

Infinities have also been similarly rare for me except in isolation.

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170627/6d8874b3/attachment.html>


More information about the es-discuss mailing list