Skip to content

Instantly share code, notes, and snippets.

@rustamgarifulin
Created July 13, 2017 19:18
Show Gist options
  • Save rustamgarifulin/e92be3d7d02b26368a165a19354cba07 to your computer and use it in GitHub Desktop.
Save rustamgarifulin/e92be3d7d02b26368a165a19354cba07 to your computer and use it in GitHub Desktop.
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 = ['день','дня','дней'];
console.log(numfix(1, a)); // день
console.log(numfix(2, a)); // дня
console.log(numfix(5, a)); // дней
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment