Skip to content

Instantly share code, notes, and snippets.

@ChillyBwoy
Created October 25, 2010 16:02
Show Gist options
  • Save ChillyBwoy/645200 to your computer and use it in GitHub Desktop.
Save ChillyBwoy/645200 to your computer and use it in GitHub Desktop.
plural ru
var pluralRu = function pluralRu(value) {
if (arguments.length != 4) throw "Wrong number of arguments"
var number = Math.abs(value),
one = arguments[1] || '', two = arguments[2] || '', five = arguments[3] || '';
number %= 100;
if (number >= 5 && number <= 20) return five;
number %= 10;
if (number == 1) return one;
if (number >= 2 && number <= 4) return two;
return five;
}
/*
usage:
pluralRu(1, 'яблоко', 'яблока', 'яблок')
pluralRu(4, 'яблоко', 'яблока', 'яблок')
pluralRu(10, 'яблоко', 'яблока', 'яблок')
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment