Skip to content

Instantly share code, notes, and snippets.

@Manimall
Forked from tomfun/plural.js
Created May 4, 2018 21:49
Show Gist options
  • Select an option

  • Save Manimall/e70601a45876775aa29c4700d23e87b0 to your computer and use it in GitHub Desktop.

Select an option

Save Manimall/e70601a45876775aa29c4700d23e87b0 to your computer and use it in GitHub Desktop.
JavaScript russian plural function
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