Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[.3,'.2',.1] sorts to [0.1, 0.3, ".2"] #30

Open
macronx opened this issue Jul 10, 2016 · 0 comments
Open

[.3,'.2',.1] sorts to [0.1, 0.3, ".2"] #30

macronx opened this issue Jul 10, 2016 · 0 comments

Comments

@macronx
Copy link

macronx commented Jul 10, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant