This is regarding the JavaScript certification project: Cash Register
I was going through my solutions for the certification projects to optimize them and realized my solution (which had passed the certification) had some flawed logic and the code was not actually working as intended. In cases where the status would be “OPEN” and change would be returned sorted in highest to lowest order, if my code ran into a currency that could be used to fulfill the amount owed and none were present (0 quarters where 50 cents is owed), it would return “INSUFFICIENT_FUNDS” status.
Here is the input that was not present in the project requirements that my solution failed on:
checkCashRegister(19.5, 20, [["PENNY", 0.50], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]])
In this case, the price is $19.50, the cash given as payment is $20 and the cash-in-drawer is $1.00 in one dollar bills and $0.50 in pennies. With the given requirements, this should have returned a status of ‘OPEN’, with change being [[“PENNY”,0.5]].
Hopefully this is helpful. I’ve since fixed this in my solution but still have the old code if any more information is needed.