Last active
May 24, 2024 17:15
-
-
Save alekstar79/7d57262bf96987d8b325f8ff0d75aca0 to your computer and use it in GitHub Desktop.
Numeric declination
This file contains hidden or 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
/** | |
* @example declination(5, ['комментарий','комментария','комментариев']) | |
* @param {Number} n The number for which the ending will be calculated | |
* @param {Array} titles Word variants for 1,2,5 | |
* @returns {String} | |
*/ | |
export function declination(n, titles) | |
{ | |
return titles[(n % 10 === 1 && n % 100 !== 11) ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment