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.

Revisions

  1. andreasvirkus created this gist Sep 30, 2024.
    16 changes: 16 additions & 0 deletions singularize.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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]
    );
    }