Skip to content

Instantly share code, notes, and snippets.

@tomfun
Created August 23, 2016 12:31
Show Gist options
  • Select an option

  • Save tomfun/830fa6d8030d16007bbab50a5b21ef97 to your computer and use it in GitHub Desktop.

Select an option

Save tomfun/830fa6d8030d16007bbab50a5b21ef97 to your computer and use it in GitHub Desktop.

Revisions

  1. tomfun created this gist Aug 23, 2016.
    15 changes: 15 additions & 0 deletions plural.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    function getNoun(number, one, two, five) {
    let n = Math.abs(number);
    n %= 100;
    if (n >= 5 && n <= 20) {
    return five;
    }
    n %= 10;
    if (n === 1) {
    return one;
    }
    if (n >= 2 && n <= 4) {
    return two;
    }
    return five;
    }