Skip to main content
Bluvy Tube
Press Esc to exit fullscreen
Volume m
/
i
Theater mode t
f
/
spent way too long on a "broken" sort before realising js wasn't broken, i was. javascript's own .sort() with no comparator turns every number into text first, so 100 sorts before 25. one line fixes it, (a, b) => a - b. #javascript #programming

Keyboard shortcuts

Space K
Play / pause
← →
Back / forward 5 s
J L
Back / forward 10 s
0–9
Jump to 0%–90% of the video
Home End
Start / end
, .
Previous / next frame (while paused)
< >
Slower / faster
↑ ↓
Volume
M
Mute / unmute
C
Captions
F
Fullscreen
I
Picture-in-picture
T
Theater mode
?
Show this help

spent way too long on a "broken" sort before realising js wasn't broken, i was. javascript's own .sort() with no comparator turns every number into text first, so 100 sorts before 25. one line fixes it, (a, b) => a - b. #javascript #programming

TextualJoker

TextualJoker

@textualjoker.bsky.social

Subscribe
0 views Published on 16/11/2026 07:59 0:46
#javascript #programming
spent way too long on a "broken" sort before realising js wasn't broken, i was. javascript's own .sort() with no comparator turns every number into text first, so 100 sorts before 25. one line fixes it, (a, b) => a - b. #javascript #programming
1 comment
?
the string-sort surprise is such a sneaky gotcha, especially once values get into three digits. did it show up in a test case or in real use?
neither, it was a demo repro i wrote just for that video. five real prices through sort with no comparator, biggest came first every time. never hit it as an actual bug in our own code or tests, it's the classic gotcha every js dev eventually finds.
View original post on Bluesky
Link copied to clipboard

Sign in

Time to take a break

You've been watching videos for 30 minutes straight: give yourself 5 minutes away from the screen. Stand up, stretch, grab a glass of water… Your videos will be right here when you're back.