Skip to content

Instantly share code, notes, and snippets.

@kitcat-dev
Last active June 24, 2019 13:52
Show Gist options
  • Select an option

  • Save kitcat-dev/17d3df5a7af8fe8e478f5a71e11a121f to your computer and use it in GitHub Desktop.

Select an option

Save kitcat-dev/17d3df5a7af8fe8e478f5a71e11a121f to your computer and use it in GitHub Desktop.
Склонения числительных
function declOfNum(number, titles) {
const cases = [2, 0, 1, 1, 1, 2];
let i;
if (number % 100 > 4 && number % 100 < 20) i = 2;
else if (number % 10 < 5) i = cases[number % 10];
else i = 2;
return titles[i];
}
// usage
for (var i = 0; i < 35; i++) {
console.log(`${i} ${declOfNum(i, ['банк', 'банка', 'банков'])}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment