Created
March 12, 2016 17:28
-
-
Save ericdke/ae8c535ef54dce1276cb to your computer and use it in GitHub Desktop.
Get strings containing non padded numbers sorted properly by numeric order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let names = ["h8", "h9", "h10", "h11", "h4", "h12", "h5", "h6"] | |
let result = names.sort { $0.compare($1, options: .NumericSearch) == .OrderedAscending } | |
result // ["h4", "h5", "h6", "h8", "h9", "h10", "h11", "h12"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment