В
Size: a a a
В
v
v
Рк
Рк
AP
VC
const bonusesCountExamples = [1, 2, 100, 4, 5, 10, 11];
bonusesCountExamples.forEach(prepareBonusText);
function prepareBonusText(bonusCount) {
/*
* если 2 то "бонуса"
* если 10 то "бонусов"
* если 1 то "бонус"
* ... и так далее
* */
}
j
function prepareBonusText(bonusCount) {
return bonusCount + ' бонус' + (bonusCount>1?bonusCount>4?'ов':'а':'')
}
VC
КК
function prepareBonusText(bonusCount) {
let text = 'бонус';
if (bonusCount === 1) return
${bonusCount} ${text}
;
if (bonusCount < 20) {
text += !bonusCount || bonusCount > 4 ? 'ов' : 'а';
} else {
const rest = bonusCount % 10;
if (rest === 1) return bonusCount + text;
text += !rest || rest > 4 ? 'ов' : 'а';
}
return
${bonusCount} ${text}
;
}
КК
j
function prepareBonusText(bonusCount, x=bonusCount%10) {
return bonusCount + ' бонус' + (x>1||bonusCount<20?x>4||bonusCount<20?'ов':'а':'')
}
КК
j
VC
function prepareBonusText(bonusCount) {
const forms = ['бонус', 'бонуса', 'бонусов'];
const hundredRemainder = bonusCount % 100;
const tenRemainder = hundredRemainder % 10;
if (hundredRemainder > 10 && hundredRemainder < 20) {
return forms[2];
}
if (tenRemainder > 1 && tenRemainder < 5) {
return forms[1];
}
if (tenRemainder === 1) {
return forms[0];
}
return forms[2];
}
j
j
КК
function prepareBonusText(bonusCount) {
const prepare = (n, text = 'бонус') =>
${bonusCount} ${n === 1 ? text : text += !n || n > 4 ? 'ов' : 'а'}
;
return prepare(bonusCount < 20 ? bonusCount : bonusCount % 10);
}
j