Created
December 19, 2017 13:24
-
-
Save faustienf/11c1c3d102d70771d2301cd1ddc5cc85 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
export function declination(num, titles) { | |
const cases = [2, 0, 1, 1, 1, 2]; | |
return titles[(num % 100 > 4 && num % 100 < 20) | |
? 2 | |
: cases[(num % 10 < 5) ? num % 10 : 5] | |
]; | |
} | |
declination(1, ['яблоко', 'яблока', 'яблок']); // яблоко | |
declination(2, ['яблоко', 'яблока', 'яблок']); // яблока | |
declination(5, ['яблоко', 'яблока', 'яблок']); // яблок |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment