Hacker News new | ask | show | jobs
by genezeta 565 days ago
It's not my intention to discard the whole article for this problem but...

   calculateTotalPrice(100, [5, 10, 15]);
And so, a base price of 100 and applying discounts of 5, 10, and 15, produces a total price of... 3000. Odd kind of discount, innit?

I mean, either this is a bad example not well thought out, or the original function is doing something completely different and the supposedly good naming is actually a very bad one since it appears to make sense but doesn't. In either case not good.

1 comments

Good catch. The total discount should be divided by 100. I missed that. :) Fixed now.
Slow down :)

- In one case you write (p/100) and in the other (totalDiscount/100). It wouldn't matter because the end result is the same mathematically, but the apparent meaning is different. But anyway...

- Now the calculated total price is 30, but it should be 70. totalPrice = basePrice * (1 - totalDiscount/100)