Created
August 27, 2021 12:57
-
-
Save Inontran/bf5e41ce1aacbaa42024982b9648aa94 to your computer and use it in GitHub Desktop.
склонение слов в зависимости от числителя
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
| //declineWord | |
| function declineWord(number, titles){ | |
| const numberOfEnding = [2, 0, 1, 1, 1, 2]; | |
| const isLastEnding = number % 100 > 4 && number % 100 < 20; | |
| const correctEnding = (number % 10 < 5) ? number % 10 : 5; | |
| return titles[isLastEnding ? 2 : numberOfEnding[correctEnding]]; | |
| //use: | |
| //declineWord(count, ['гость', 'гостя', 'гостей']); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment