Last active
August 29, 2015 13:57
-
-
Save porqz/9447060 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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