Skip to content

Instantly share code, notes, and snippets.

@crrmacarse
Last active January 28, 2020 07:41
Show Gist options
  • Save crrmacarse/87ac37ed6d5693deb68dc67bb05cc78d to your computer and use it in GitHub Desktop.
Save crrmacarse/87ac37ed6d5693deb68dc67bb05cc78d to your computer and use it in GitHub Desktop.
Pluralize a word!
const pluralize = word => {
const wordArr = word.split('')
const suffix = wordArr.pop()
switch (suffix) {
case 's':
case 'z':
case 'x':
return `${wordArr.join('')}${suffix}es`
case 'y':
return `${wordArr.join('')}ies`
default:
return `${wordArr.join('')}${suffix}s`
}
}
export default pluralize;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment