Skip to content

Instantly share code, notes, and snippets.

@youmee
Last active January 16, 2020 14:20
Show Gist options
  • Save youmee/bc23dd6088e59609609f to your computer and use it in GitHub Desktop.
Save youmee/bc23dd6088e59609609f to your computer and use it in GitHub Desktop.
Swift Russian Plural Form Function
/*
pluralForm(28, forms: ["год", "года", "лет"])
output: "лет"
*/
func pluralForm(number: Int, forms: [String]) -> String {
return number % 10 == 1 && number % 100 != 11 ? forms[0] :
(number % 10 >= 2 && number % 10 <= 4 && (number % 100 < 10 || number % 100 >= 20) ? forms[1] : forms[2])
}
@Xopoko
Copy link

Xopoko commented Jan 17, 2017

Thanks dude!

@youmee
Copy link
Author

youmee commented Sep 13, 2017

@Xopoko you're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment