Ad
  • Custom User Avatar

    Hi.

    I think you can add another test, because my script has passed when it shouldn't.

    If you try this:

    var vm = new VendingMachine({1:0, 3:2, 5:1, 8:0});

    vm.vending(9, {8:2});

    As the price is 9 and I put 16 coins (8x2), the machine should return a change of 7, but it hasn't enough coins for that. According to the description, the machine should return the closest value to the expected change. In this case the closest value is 6 (3x2).

    As I mentioned, my script has passed the test cases, but if you try the example above, you'll see my script returns a change of 5 (5x1), so I suppose you can add a test case like this to ensure the scripts are well-constructed.

    Of course, I will improve my solution to pass this kind of test too.