Last active
January 10, 2019 09:07
-
-
Save RomiC/0df84d7171a7f3c4e34ba4fac3cc94d7 to your computer and use it in GitHub Desktop.
Simple pluralize function for Russian language
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
function pluralize(quantity, options) { | |
/** | |
* options: [ | |
* 0 -> товар | |
* 1 -> товара | |
* 2 -> товаров | |
* ] | |
*/ | |
const remainder = (quantity %= 100, quantity > 14 ? quantity % 10 : quantity); | |
return options[remainder === 1 ? 0 : remainder > 1 && remainder < 5 ? 1 : 2]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment