Skip to content

Instantly share code, notes, and snippets.

@alpacato
Forked from realmyst/gist:1262561
Last active March 19, 2018 15:30
Show Gist options
  • Save alpacato/2ddf835bc54a3ba6a45251050105ee26 to your computer and use it in GitHub Desktop.
Save alpacato/2ddf835bc54a3ba6a45251050105ee26 to your computer and use it in GitHub Desktop.
Склонение числительных в javascript
const declOfNum = (number, titles) => {
let cases = [2, 0, 1, 1, 1, 2];
return titles[(number % 100 > 4 && number % 100 < 20) ? 2 : cases[(number % 10 < 5) ? number % 10 : 5]];
}
// use:
const number = 100;
declOfNum(number, ['найдена', 'найдено', 'найдены']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment