Skip to content

Instantly share code, notes, and snippets.

@sensonicm
Created August 13, 2019 12:08
Show Gist options
  • Save sensonicm/da455832ceac565ac7083eb5813c7575 to your computer and use it in GitHub Desktop.
Save sensonicm/da455832ceac565ac7083eb5813c7575 to your computer and use it in GitHub Desktop.
Russian plural function
function plural_str(i, str1, str2, str3){
function plural (a){
if ( a % 10 == 1 && a % 100 != 11 ) return 0
else if ( a % 10 >= 2 && a % 10 <= 4 && ( a % 100 < 10 || a % 100 >= 20)) return 1
else return 2;
}
switch (plural(i)) {
case 0: return str1;
case 1: return str2;
default: return str3;
}
}
example:
var num = 12;
plural_str(num, ‘товар’,'товара’,'товаров’); // 12 товаров
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment