Skip to content

Instantly share code, notes, and snippets.

@dimasch
Forked from tomfun/plural.js
Created June 30, 2017 05:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimasch/767203178c696a5952bdb2690fa84354 to your computer and use it in GitHub Desktop.
Save dimasch/767203178c696a5952bdb2690fa84354 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