javascript-natural-sort
javascript-natural-sort copied to clipboard
[.3,'.2',.1] sorts to [0.1, 0.3, ".2"]
I hope this isn't duplicated elsewhere.
[.3,'.2',.1].sort(naturalSort)
[0.1, 0.3, ".2"]
Seems that the floating point regex requires an integer part, so the '.2' is chunked to ['.', 2] while the non-string numbers are recognized by javascript as numbers and are not chunked.
Changing /\d+(?:.\d_)?/ to /(?:\d+(?:.\d_)?|.\d+)/ resolves this, but I don't know if it breaks other unit tests and haven't used github long enough to feel comfortable contributing to "live" code (and may not have the required tools installed).
original: sign? integer fraction? exponent? modified: sign? ( integer fraction? | fraction ) exponent? // second fraction requires digits