Skip to content

Instantly share code, notes, and snippets.

@znechai
Last active April 2, 2024 03:03
Show Gist options
  • Star 26 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save znechai/1b25d0ee9a92e5b879175ab4f040dbbc to your computer and use it in GitHub Desktop.
Save znechai/1b25d0ee9a92e5b879175ab4f040dbbc 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