Problem with Floating Point Values in **Exact Change** Advanced Algorithm Challenge

Problem with Floating Point Values in **Exact Change** Advanced Algorithm Challenge
0.0 0

#1

Hi guys, I have been dealing with this for more than an hour, but I can’t figure out myself. I pass al the test except for checkCashRegister(3.26, 100.00, [[“PENNY”, 1.01], [“NICKEL”, 2.05], [“DIME”, 3.10], [“QUARTER”, 4.25], [“ONE”, 90.00], [“FIVE”, 55.00], [“TEN”, 20.00], [“TWENTY”, 60.00], [“ONE HUNDRED”, 100.00]]) should return [[“TWENTY”, 60.00], [“TEN”, 20.00], [“FIVE”, 15.00], [“ONE”, 1.00], [“QUARTER”, 0.50], [“DIME”, 0.20], [“PENNY”, 0.04]].
When I look at the output in the console, it seems the same as expected output, but I don’t know the reason it fails. I will appreciate your help. Here is the link to my code: https://jsfiddle.net/do91m6qy/


#2

Hey there!

I had a quick look and just dug around the code a bit and looked at the output, it looks the what is being returned (changeArr) is not formatted from highest to lowest as specified in the challenge. You can see this if you wrap the function call with console.log:

console.log(checkCashRegister(3.26, 100.00, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.10], ["QUARTER", 4.25], ["ONE", 90.00], ["FIVE", 55.00], ["TEN", 20.00], ["TWENTY", 60.00], ["ONE HUNDRED", 100.00]]));

I also had another look at the challenge, and if I’m not mistaken, it’s because all other test cases do not require you to have an output that sorts from highest to lowest—they are either “Insufficient fund”, “closed” or a just an array of a single array.

I hope that helps! :slight_smile:


#3

@honmanyau Thank you very much! I guess you have finished all of challenges already :smiley:


#4

@curiousNoob You are welcome! Other than not having reversed the array you have basically finished it—I just happen to remember that challenge because it’s interesting, and I remember telling myself to reverse the array so I spotted that it wasn’t in your case in right away. :slight_smile:

Good luck with other challenges!