Skip to content

Instantly share code, notes, and snippets.

@zerc
Last active December 18, 2015 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerc/5840838 to your computer and use it in GitHub Desktop.
Save zerc/5840838 to your computer and use it in GitHub Desktop.
var plural = function(number, one, two, five) {
var n = Math.abs(number);
n %= 100;
if (n >= 5 && n <= 20) return number + ' ' + five;
n %= 10;
if (n == 1) return number + ' ' + one;
if (n >= 2 && n <= 4) return number + ' ' + two;
return number + ' ' + five;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment