function pluralization choice choicesLength singular used for numbers

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
function pluralization(choice, choicesLength) {
// singular used for numbers ending in 1, except 11 (1, 21, 31...)
// special case for numbers ending in 2-4, except 12-14 (2-4, 22-24, 32-34...)
// numbers ending in 11-14 use plural (11-14, 111-114, 211-214...)
var singular = (choice % 10 === 1 && choice % 100 != 11);
if (choicesLength === 2) return singular ? 0 : 1;
var few = (choice % 10 >= 2 && choice % 10 <= 4 && (choice % 100 < 10 || choice % 100 >= 20));
return singular ? 0 : few ? 1 : 2;
}