Skip to content

Instantly share code, notes, and snippets.

@AlexKalinin
Forked from realmyst/gist:1262561
Last active April 10, 2016 08:39
Show Gist options
  • Save AlexKalinin/49fdeccda74ac65c2c32f43c43fc2631 to your computer and use it in GitHub Desktop.
Save AlexKalinin/49fdeccda74ac65c2c32f43c43fc2631 to your computer and use it in GitHub Desktop.
Склонение числительных в javascript
function declOfNum(number, titles) {
var cases = [2, 0, 1, 1, 1, 2];
return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];
}
//usage:
var num = 15;
declOfNum(num, ['товар', 'товара', 'товаров']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment