Skip to content

Instantly share code, notes, and snippets.

@victorpavlenko
Created June 19, 2015 08:26
Show Gist options
  • Save victorpavlenko/7872c5a7a167bae71563 to your computer and use it in GitHub Desktop.
Save victorpavlenko/7872c5a7a167bae71563 to your computer and use it in GitHub Desktop.
ь, я, ей
var forms = 'рубль,рубля,рублей'.split(',')
/* Алгориииитм! */
function getForm(x) {
var x10 = x % 10, x100 = x % 100, form = 2 // рублей
if (x10 == 1 && x100 != 11)
form = 0 // рубль
else if (x10 > 1 && x10 < 5 && (x100 < 10 || x100 > 21))
form = 1 // рубля
return forms[form]
}
/* Ненаучный тест */
var res = ''
for (var i = 0; i < 26; ++i) {
res += i + ' ' + getForm(i) + '<br>'
}
res += '...<br>'
for (var i = 100; i < 126; ++i) {
res += i + ' ' + getForm(i) + '<br>'
}
document.getElementById('out').innerHTML = res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment