Так можно сделать
function cart(basketAmount, countGoods, promo = null) {
let discountAmount = 0;
let rules = [
(result) => {
return (promo === "ДАРИМ300")? result - 300 : result;
},
(result) => {
return (countGoods >= 10)? result * 0.95 : result;
},
(result) => {
return (result > 50000)? result - (50000 - result) * 0.2 : result
},
(result) => {
return (promo === "СКИДКА15" && result >= 20000)? result * 0.85 : result;
}
];
let result = basketAmount;
for (let f of rules) {
result = f(result);
if (result <= 0) {
result = 0;
break;
}
}
return result;
}
console.log(cart(80000, 20, "СКИДКА15")); // 69020 А сколько должно быть?