Created
February 12, 2019 15:22
-
-
Save acidka/d3d63992ffb5d84394381bd5a420f790 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
| /** | |
| * Функция возвращает окончание для множественного числа слова на основании числа и массива окончаний | |
| * @param iNumber Integer Число на основе которого нужно сформировать окончание | |
| * @param aEndings Array Массив слов или окончаний для чисел (1, 4, 5), | |
| * например ['яблоко', 'яблока', 'яблок'] | |
| * @return String | |
| */ | |
| function formatByCount(number, form1, form2, form3) | |
| { | |
| var count = Math.abs(number) % 100; | |
| var lCount = number % 10; | |
| if (count >= 11 && count <= 19) { | |
| return form3; | |
| } | |
| if (lCount >= 2 && lCount <= 4) { | |
| return form2; | |
| } | |
| if (lCount == 1) { | |
| return form1; | |
| } | |
| return form3; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment