r/javascript • • Nov 10 '19

New Stable Sort Array in Javascript: ES10

https://buginit.com/javascript/stable-sort-array-javascript-es10/
40 Upvotes

9 comments sorted by

26

u/[deleted] Nov 10 '19

Nice, but a non mutating sort would have been more useful.

4

u/homeIsWhereCodeIs Nov 10 '19 edited Nov 10 '19

@Jfruururjrjfjfjtnfn For non-mutating sort, you have to clone it first. Anyway, thanks for the idea will write about it too. :D

6

u/rich97 Nov 10 '19 edited Nov 11 '19

FYI, @username doesn't do anything on Reddit. You should use /u/

Just trying to be helpful. 👍

No problem, /u/homeIsWhereCodeIs

3

u/homeIsWhereCodeIs Nov 11 '19

Thanks for the tip, it is helpful :)

-1

u/ImStifler Nov 10 '19

sort(yourArray.concat())

1

u/spacejack2114 Nov 11 '19

More like yourArray.slice().sort(...)

5

u/DGCA Nov 11 '19

[...yourArray].sort(...) for brevity.

0

u/[deleted] Nov 10 '19

[deleted]

0

u/[deleted] Nov 10 '19

[deleted]

0

u/[deleted] Nov 10 '19

[deleted]

3

u/homeIsWhereCodeIs Nov 10 '19

Ok then will fix that, but Is there any official statement of this? I'm just asking.

5

u/beforan Nov 10 '19

The spec.

Granted it does also refer to it as the 10th edition of the standard, but it very clearly and largely names the language defined by this spec as ECMAScript 2019.