I want to sort an array of strings so that alphabetic characters are always before any other kinds of characters. For example:
[\"800\", \"word\", \"test\"]
How about this.
func sortedNumbersLast(words: [String]) -> [String] {
var startsWithDigit = [String]()
var startsWithCharacter = [String]()
for word in words {
if let first = word.characters.first {
if first >= "0" && first <= "9" {
startsWithDigit.append(word)
}
else {
startsWithCharacter.append(word)
}
}
}
return startsWithCharacter.sort(<) + startsWithDigit.sort(<)
}