Skip to content

Instantly share code, notes, and snippets.

@porqz
Last active August 29, 2015 13:57
Show Gist options
  • Save porqz/9447060 to your computer and use it in GitHub Desktop.
Save porqz/9447060 to your computer and use it in GitHub Desktop.
/**
* Chooses plural form of a word that corresponds to a number
*
* @param {number} number The number
* @param {string} zeroCaseForm Zero-ending form (ворон)
* @param {string} oneCaseForm One-ending form (ворона)
* @param {string} twoCaseForm Two-ending form (вороны)
*
* @returns {string} Plural form of the word
*/
function getPluralForm(number, zeroCaseForm, oneCaseForm, twoCaseForm) {
var lastDigit = String(number).slice(-1);
switch (lastDigit) {
case '0':
case '9':
case '8':
case '7':
case '6':
case '5':
return zeroCaseForm;
case '4':
case '3':
case '2':
return twoCaseForm;
case '1':
return oneCaseForm;
default:
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment