• The user can modify the groceries.

  • First of all, I would like to say that I appreciate the people who spend time and create the katas.
    Thank you.
    I just want you to know that I am not just criticizing by posting this.
    I want to understand what is going on so I can attempt this kata.

    In general, I don't understand how the bogof items work. I know what it stands for. But, how can there ever be an odd amount for them? If you buy one, you get a free one. There is always an even number.

    Specifically: In the one example in the description, the amount for Chocolate is 5 and OJ is 15. This is supposed to return 26.25 according to the description. So, to work it out on paper...err...in the computer...whatever...

    OJ would be:
    15 .x 1.5 = 22.5
    22.5 - 2.25 (10% discount) = 20.25

    So, that means the Chocolate should cost $6. No discount amount.
    How is this calculated with a price of 2?
    The only thing I can figure out is that you would round up to the next integer for half of an odd item amount for a bogof item to solve this kata. So, you would use 3 for this test case.

  • Thank you. I passed the tests already

  • Hi- thanks for your feedback, have you now submitted a solution? If you are still having problems with the tests please let me know and I'll look into it.

  • Thanks for completing the kata! That's a great idea- I was definitely thinking of doing a more complicated version and increasing the difficulty.

  • PHP Translation Kumited - please carefully review and approve :D

  • I had fun with this but also some problems passing the random tests. Maybe is my code.

  • Nice kata! You could make an alternate version of this kata with duplicated items, and items not contained in the object list.

  • Great! Thanks for your help :)

  • Found it! There was still a reference to the subarray you added to the two arrays. I fixed your tests and now it works even with array manipulation :)

  • Well, it worked now. But you don't have to work with two arrays in this case. That didn't solve my problem. My initial solution also failed. I just removed the array manipulation of the input and now it works. Seems like I also changed the input array of your check solution, so the amount of every item with the attribut "bogof" is divided by 2. There is a reference somehow, but I don't know how to fix this.

  • Thanks- I think I've managed to track down the issue, it was relating to how the arrays were passed into the solution function and my testing function. It should now be fixed, could you try out your solution again and let me know if the expected values are now working for you?

  • Thanks! and many thanks for completing my kata :)

  • Hi zruF - Thanks for trying out my kata. I can't work out what's happening here, unless something is changing in the global object. I've run the array [ [ 'Apples', 75 ], [ 'Pears', 9 ], [ 'Chocolate', 15 ] ] directly into the Random test check and it gives the correct expected answer of 475. Is this only happening for arrays containing Chocolate?

  • Don't worry ;)

  • Loading more items...