Skip to content

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

@macronx

Description

@macronx

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions