Pluralisation is the act of making a singular word to its plural equivilent. For example, baby should equal babies and student should equal students.
I was thinking how difficult this would be to do in code without asking users to type both singular and plural in.
So I have come up with the following function that should convert a given word into its plural equivilent. It should also take care of if a word is already plural. I have written both methods in C# and JavaScript below. There are few changes between them.
public string Pluralise(string word) {
if (word[word.Length - 1] == 's')
return word;
if (name[word.Length - 1] == 'y' && word[word.Length - 2] != 'e')
return word.Substring(0, word.Length - 1) + "ies";
return word + "s";
}
JavaScript
function Pluralise(word) {
if (word[word.length - 1] == 's')
return word;
if (word[word.length - 1] == 'y' && word[word.length - 2] != 'e')
return word.substring(0, word.length - 1) + "ies";
return name + "s";
}