Skip to content

Instantly share code, notes, and snippets.

@mihdan
Forked from znechai/pluralize-ru.js
Created January 18, 2023 13:25
Show Gist options
  • Save mihdan/e0d77e258015c619d141663d48a1d2af to your computer and use it in GitHub Desktop.
Save mihdan/e0d77e258015c619d141663d48a1d2af to your computer and use it in GitHub Desktop.
JavaScript - Plural forms for russian words
/**
* Plural forms for russian words
* @param {Integer} count quantity for word
* @param {Array} words Array of words. Example: ['депутат', 'депутата', 'депутатов'], ['коментарий', 'коментария', 'комментариев']
* @return {String} Count + plural form for word
*/
function pluralize(count, words) {
var cases = [2, 0, 1, 1, 1, 2];
return count + ' ' + words[ (count % 100 > 4 && count % 100 < 20) ? 2 : cases[ Math.min(count % 10, 5)] ];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment