function plural(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] ];
}
var declension = ['год', 'года', 'лет'];
console.log('1 ', plural(1, declension));
console.log('2 ', plural(2, declension));
console.log('5 ', plural(5, declension));
console.log('7 ', plural(6, declension));
console.log('10 ', plural(10, declension));
console.log('20 ', plural(20, declension));