Skip to content

Instantly share code, notes, and snippets.

@itorgov
Forked from tomfun/plural.js
Last active March 5, 2020 13:45
Show Gist options
  • Save itorgov/14436aa7ffba1f521a2c30b016ae9ef9 to your computer and use it in GitHub Desktop.
Save itorgov/14436aa7ffba1f521a2c30b016ae9ef9 to your computer and use it in GitHub Desktop.
JavaScript plural function for Russian language.
function getNoun(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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment