commit 67308d3ec33bade8513a219059cf35f5a94ae7e7 Author: Erik C. Thauvin Date: Sun Aug 28 00:26:21 2016 -0700 diff --git a/Plural.kt b/Plural.kt new file mode 100644 index 0000000..376ccfd --- /dev/null +++ b/Plural.kt @@ -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" +} \ No newline at end of file