Тож моё
function pluralize(count, base, ending1, ending2, ending3) { if (ending3 === undefined) { base += count == 1? ending1 : ending2; } else { var _ = count % 100 > 20 ? count % 10 : count; base += _ == 0 || _ > 4 ? ending3 : _ > 1 ? ending2 : ending1; } return count + ' ' + base; }
undefined
pluralize(0, 'comment', '', 's')
"0 comments"
pluralize(1, 'comment', '', 's')
"1 comment"
pluralize(3, 'comment', '', 's')
"3 comments"
pluralize(1, 'wol', 'f', 'ves')
"1 wolf"
pluralize(2, 'wol', 'f', 'ves')
"2 wolves"
pluralize(1, 'волк', '', 'а', 'ов') + ' и ' + pluralize(7, 'козл', 'енок', 'енка', 'ят')
"1 волк и 7 козлят"
pluralize(1, 'робот', '', 'а', 'ов')
"1 робот"
pluralize(113, 'робот', '', 'а', 'ов')
"113 роботов"
pluralize(244, 'робот', '', 'а', 'ов')
"244 робота"
pluralize(576, 'робот', '', 'а', 'ов')
"576 роботов"