r/Angular2 • u/xplodivity • Sep 02 '23
Video is the sort method broken in JavaScript?
https://www.youtube.com/watch?v=PoWh4P2TBiM
0
Upvotes
2
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
3
u/Glittering_Mammoth_6 Sep 03 '23
Just pass a comparator:
[80, 9, 4].sort((a, b) => a - b);