oleeskild / digitalgarden

275 stars 158 forks source link

Fix sorting order for numeric strings #186

Closed F4bbi closed 4 months ago

F4bbi commented 1 year ago

I have noticed that since strings are compared using alphabetical order, if they start with a number they won't be compared correctly. For example, '10' will be placed before '2' in the sorted results. So, I tried to fix this problem using a regular expression that extracts the numeric portion at the beginning of each string (if it's possible) and performs a numerical comparison. See an example below.

image

oleeskild commented 4 months ago

Awesome! Thank you so much!