Medium
You're developing an e-commerce checkout system that needs to process multiple discount codes. What's wrong with this implementation?
1async function applyDiscounts(cart, discountCodes) {2 let totalDiscount = 0;34 discountCodes.forEach(async (code) => {5 const discount = await fetchDiscountValue(code);6 totalDiscount += discount;7 });89 return {10 ...cart,11 totalDiscount,12 finalPrice: cart.originalPrice - totalDiscount13 };14}1516// Usage17const cart = { originalPrice: 100 };18const codes = ['SUMMER', 'WELCOME'];19console.log(await applyDiscounts(cart, codes));