Skip to content

Instantly share code, notes, and snippets.

@RomiC
Last active January 10, 2019 09:07
Show Gist options
  • Save RomiC/0df84d7171a7f3c4e34ba4fac3cc94d7 to your computer and use it in GitHub Desktop.
Save RomiC/0df84d7171a7f3c4e34ba4fac3cc94d7 to your computer and use it in GitHub Desktop.
Simple pluralize function for Russian language
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