JavaScriptKatas icon indicating copy to clipboard operation
JavaScriptKatas copied to clipboard

fix: Small bug in potter Kata

Open voghDev opened this issue 2 years ago • 0 comments

Hi!

After summoning this repo, I've found a small bug in the potter kata. The problem was that groupBooks was returning a map with a structure like:

{
  "1": 1,
  "2": 2,
  "3": 1,
  ... 
}

and after decreasing the counter inside removeDiscountedBooks, we could have

{
  "1": 0,
  "2": 1,
  "3": 0,
  ... 
}

so, when obtaining books[0], we could get a 0 instead of a 1, which calculates a wrong price. Instead of getting 8 * 1 = 8, we would get 8 * 0 = 0.

One possible solution would be to remove the entries from the Map where the value is 0 in removeDiscountedBooks. I wrote it in this PR. I Hope you find it useful :smiley:

I've added a test that makes the current master branch fail. If you remove the .filter() in this PR, you will see that the test expects 38 and gets 30.

voghDev avatar Feb 13 '23 09:02 voghDev