Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created September 30, 2024 12:49
Show Gist options
  • Save andreasvirkus/0fc10cd83ff886ab22c1b232f206262f to your computer and use it in GitHub Desktop.
Save andreasvirkus/0fc10cd83ff886ab22c1b232f206262f to your computer and use it in GitHub Desktop.
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