Passer au contenu principal
Bluvy Tube
Appuyez sur Échap pour quitter le plein écran
Volume m
/
i
Mode Cinéma 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

Raccourcis clavier

Espace K
Lecture / pause
← →
Reculer / avancer de 5 s
J L
Reculer / avancer de 10 s
0–9
Aller à 0 %–90 % de la vidéo
Home End
Début / fin
, .
Image précédente / suivante (en pause)
< >
Ralentir / accélérer
↑ ↓
Volume
M
Couper / rétablir le son
C
Sous-titres
F
Plein écran
I
Image dans l’image
T
Mode cinéma
?
Afficher cette aide

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

S'abonner
0 vue Publié le 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 commentaire
?
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.
Voir le post d'origine sur Bluesky
Lien copié dans le presse-papier

Connexion

Il est temps de faire une pause

Ça fait 30 minutes que vous enchaînez les vidéos : accordez-vous 5 minutes loin de l'écran. Levez-vous, étirez-vous, buvez un verre d'eau… Les vidéos vous attendront ici.