Created
March 5, 2016 00:42
-
-
Save maml/fe1803494e7c8d48d7bf to your computer and use it in GitHub Desktop.
For a given Int you can get the appropriate suffx
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
extension Int { | |
public func suffix() -> String { | |
let absSelf = abs(self) | |
switch (absSelf % 100) { | |
case 11...13: | |
return "th" | |
default: | |
switch (absSelf % 10) { | |
case 1: | |
return "st" | |
case 2: | |
return "nd" | |
case 3: | |
return "rd" | |
default: | |
return "th" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment