Refactor Repeated Discount Calculations in a Shopping Cart

Multiple products have their discounted prices calculated with repeated code. Refactor the discount logic into a reusable applyDiscount function and update the price calculations so that the console output remains the same.
JavaScript
Console