Skip to content

Instantly share code, notes, and snippets.

@monochromer
Last active April 10, 2018 05:36
Show Gist options
  • Save monochromer/e584fc7ef1d7877dc9ab58f0fcd12539 to your computer and use it in GitHub Desktop.
Save monochromer/e584fc7ef1d7877dc9ab58f0fcd12539 to your computer and use it in GitHub Desktop.
Склонение слов
//склонение окончаний
function declension(num, expressions) {
var result;
count = num % 100;
if (count >= 5 && count <= 20) {
result = expressions[2];
} else {
count = count % 10;
if (count == 1) {
result = expressions[0];
} else if (count >= 2 && count <= 4) {
result = expressions[1];
} else {
result = expressions[2];
}
}
return result;
}
function pluralize(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;
}
alert ( declension(1, ['пользователь','пользователя','пользователей']) );
alert ( declension(2, ['пользователь','пользователя','пользователей']) );
alert ( declension(5, ['пользователь','пользователя','пользователей']) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment