Last active
January 28, 2020 07:41
-
-
Save crrmacarse/87ac37ed6d5693deb68dc67bb05cc78d to your computer and use it in GitHub Desktop.
Pluralize a word!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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