Last active
February 19, 2018 09:47
-
-
Save axjs/ad4e4087a8969f806d90a64b27f1f1c1 to your computer and use it in GitHub Desktop.
numfix
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
const numfix = (n, t) => t[ | |
(n %= 100, 20 > n && n > 4) ? 2 | |
:[2,0,1,1,1,2][ (n %= 10, n < 5) ? n : 5] | |
] | |
; | |
const a = ['день','дня','дней']; | |
numfix(1, a) // день | |
numfix(2, a) // дня | |
numfix(5, a) // дней |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment