1
0
Fork 0
mirror of https://gist.github.com/7ed3c3ef3b56e47b27dbf6153da0d7d9.git synced 2025-04-24 13:27:10 -07:00
This commit is contained in:
Erik C. Thauvin 2016-08-28 00:26:21 -07:00 committed by GitHub
commit 67308d3ec3

17
Plural.kt Normal file
View file

@ -0,0 +1,17 @@
fun String.plural(size: Int): String {
val consonants = "bcdfghjklmnpqrstvwxz"
if (size > 1 && this.length > 2) {
if ((this.endsWith("o", true) || this.endsWith("s", true)) &&
consonants.contains(this[this.length - 2], true)) {
return this + "es"
}
if (this.endsWith("y", true) &&
consonants.contains(this[this.length - 2], true)) {
return this + "ies"
}
}
return this + "s"
}