Skip to content

Instantly share code, notes, and snippets.

@ivan1911
Forked from realmyst/gist:1262561
Last active June 5, 2016 12:45
Show Gist options
  • Save ivan1911/5327202 to your computer and use it in GitHub Desktop.
Save ivan1911/5327202 to your computer and use it in GitHub Desktop.
Javascript склонение для числительных
function declOfNum(number, titles) {
cases = [2, 0, 1, 1, 1, 2];
return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];
}
use:
declOfNum(count, ['найдена', 'найдено', 'найдены']);
@lampaa
Copy link

lampaa commented Jan 14, 2016

function declOfNum(number, titles) {  
    number = Math.abs(number);
    var cases = [2, 0, 1, 1, 1, 2];  
    return number + ' ' + titles[(number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5]];  
}

@pvolyntsev
Copy link

Спасибо за исправленный вариант!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment