Created
September 30, 2024 12:49
-
-
Save andreasvirkus/0fc10cd83ff886ab22c1b232f206262f to your computer and use it in GitHub Desktop.
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
function singularize(word) { | |
const endings = { | |
ves: 'fe', | |
ies: 'y', | |
i: 'us', | |
zes: 'ze', | |
ses: 's', | |
xes: 'x', | |
es: 'e', | |
s: '' | |
}; | |
return word.replace( | |
new RegExp(`(${Object.keys(endings).join('|')})$`), | |
r => endings[r] | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment