Deep logic bug?

Hey FreeCodeCamp!
I think I found a logic bug in your formal solution.
If you try to run your solution with this input:

checkCashRegister(18.7, 20.0, [
[“PENNY”, 0],
[“NICKEL”, 0],
[“DIME”, 0.3],
[“QUARTER”, 0.25],
[“ONE”, 1],
[“FIVE”, 0],
[“TEN”, 0],
[“TWENTY”, 0],
[“ONE HUNDRED”, 0]
]);

Expected output: “ONE”:1, “DIME”:0.3
Actual output: “INSUFFICIENT_FUNDS”

So…What’s going on here? I thought about this challenge a lot…
There is somthing deeper here I think, and I’m not sure how to write algorithm for all cases…
Any help?
Thanks!

Challenge: Cash Register

Link to the challenge:

luckily, the tests do not include a situation like this

the issue here is because the expected solution just checks the denominations from highest to lowest, giving as much as possible of each one, so after giving 1.25$ in ones and quarters, you can’t give 0.05$ in dimes

the actual algorithm used by real cash registers, is more complex than this

2 Likes

Thanks @ilenia for your response!
It’s really interesting to inspect the actual algorithm used by real cash registers, I’ll think about it )