alphacyberranger to Programmer Humor@programming.dev • 2 years agoI'll just sort it myselfsh.itjust.worksimagemessage-square62fedilinkarrow-up1929arrow-down112
arrow-up1917arrow-down1imageI'll just sort it myselfsh.itjust.worksalphacyberranger to Programmer Humor@programming.dev • 2 years agomessage-square62fedilink
minus-square@jormaig@programming.devlinkfedilink3•2 years agoOnly if one of them is a string right? If you have only numbers then it works fine right? Right? (Please say that I’m right 😭)
minus-square@kevincox@lemmy.mllinkfedilink5•edit-22 years agoNo. It always compares by converting to string. I actually think this is more consistent then having different behaviour if you have a string somewhere in your list. Basically the default comparator is a.sort((a, b) => `${a}` < `${b}` ? -1 : 1).
Only if one of them is a string right? If you have only numbers then it works fine right? Right? (Please say that I’m right 😭)
No. It always compares by converting to string. I actually think this is more consistent then having different behaviour if you have a string somewhere in your list.
Basically the default comparator is
a.sort((a, b) => `${a}` < `${b}` ? -1 : 1)
.