A retailer is having a store-wide "buy 2, get 1 free" sale. For legal reasons, they can't charge their customers $0 for an article so a discount is applied to all products instead. For example, if a customer gets three products a, b and c:
| Product A | Product B | Product C |
|---|---|---|
| $15.99 | $23.50 | $10.75 |
She gets the cheapest one for free, so she ends up paying $15.99 + $23.50 = $39.49, but what her receipt says is:
Create a function that takes an array of prices for a customer's shopping cart and returns the prices with the discount applied. Round all prices to the cent.
discount([2.99, 5.75, 3.35, 4.99]) ➞[2.47, 4.74, 2.76, 4.12]
// First product for free.
discount([10.75, 11.68]) ➞ [10.75, 11.68]
// No discounts applied.
discount([68.74, 17.85, 55.99]) ➞ [60.13, 15.62, 48.98]
// Second product for free.
discount([5.75, 14.99, 36.83, 12.15, 25.30, 5.75, 5.75, 5.75]) ➞ [5.16, 13.45, 33.06, 10.91, 22.71, 5.16, 5.16, 5.16]
// First and sixth products for free (see second note).