Last active
January 13, 2018 18:25
-
-
Save robtimp/f5c9ebf6ed99631f1002418ee660c5f5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
func ordinal(forNumber: Int) -> String { | |
let tens = (number / 10) % 10 | |
let ones = number % 10 | |
let suffix: String | |
switch (tens, ones) { | |
case (1, _): | |
suffix = "th" | |
case (_, 1): | |
suffix = "st" | |
case (_, 2): | |
suffix = "nd" | |
case (_, 3): | |
suffix = "rd" | |
default: | |
suffix = "th" | |
} | |
return "\(number)\(suffix)" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, this was useful!