digitalgarden icon indicating copy to clipboard operation
digitalgarden copied to clipboard

Fix sorting order for numeric strings

Open F4bbi opened this issue 2 years ago • 0 comments

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

F4bbi avatar Jun 26 '23 20:06 F4bbi