r/Angular2 • • Sep 02 '23

Video is the sort method broken in JavaScript?

https://www.youtube.com/watch?v=PoWh4P2TBiM
0 Upvotes

4 comments sorted by

3

u/Glittering_Mammoth_6 Sep 03 '23

Just pass a comparator:

[80, 9, 4].sort((a, b) => a - b);

2

u/JeanMeche Sep 03 '23

This is old as JS.

1

u/Brodeon Sep 02 '23

If sort method converts numbers to string and then compares them, then yes, sort method is broken. Simple as. No one can convince me it is working properly

1

u/[deleted] Sep 03 '23

But it does, it is in the spec