minus-squareKiofKi@feddit.detoProgrammer Humor@programming.dev•I'll just sort it myselflinkfedilinkarrow-up15·1 year ago"By default, the sort() function sorts values as strings. This works well for strings (“Apple” comes before “Banana”). However, if numbers are sorted as strings, “25” is bigger than “100”, because “2” is bigger than “1”. Because of this, the sort() method will produce incorrect result when sorting numbers." https://www.w3schools.com/js/js_array_sort.asp linkfedilink
minus-squareKiofKi@feddit.detoMemes@lemmy.ml•Scrubs is pretty goodlinkfedilinkarrow-up12·1 year ago*Jordan’s Brother linkfedilink
minus-squareKiofKi@feddit.detoMemes@lemmy.ml•Who cares to touch the grass?linkfedilinkarrow-up28·1 year agoEven better, easier sorting. linkfedilink
"By default, the sort() function sorts values as strings.
This works well for strings (“Apple” comes before “Banana”).
However, if numbers are sorted as strings, “25” is bigger than “100”, because “2” is bigger than “1”.
Because of this, the sort() method will produce incorrect result when sorting numbers."
https://www.w3schools.com/js/js_array_sort.asp