Update instructions.md on Expenses execise (last concept in golang)

Switch the return values for p1 and p2 so that:

CategoryExpenses(records, p1, "rent")
// => 0, nil

CategoryExpenses(records, p2, "rent")
// => 1300, nil

instead of:

CategoryExpenses(records, p1, "rent")
// => 1300, nil

CategoryExpenses(records, p2, "rent")
// => 0, nil

Thanks. This looks correct to me. I’ll let the Go maintainers take a look :slight_smile:

1 Like

The current instructions are correct.

This should return 1300:

CategoryExpenses(records, p1, "rent")

Because:

p1 := DaysPeriod{From: 1, To: 30}

And there is just a single record for the rent category in this period:

{Day: 28, Amount: 1300, Category: "rent"}

Hence, the 1300 comes from the Amount of this record.

By contrast, this should return 0:

CategoryExpenses(records, p2, "rent")

Because:

p2 := DaysPeriod{From: 31, To: 60}

And records doesn’t actually have any record for any day after day 28:

records := []Record{
  {Day: 1, Amount: 15, Category: "groceries"},
  {Day: 11, Amount: 300, Category: "utility-bills"},
  {Day: 12, Amount: 28, Category: "groceries"},
  {Day: 26, Amount: 300, Category: "university"},
  {Day: 28, Amount: 1300, Category: "rent"},
}
3 Likes

Hi,

Thank you for the feedback, and I apologize for the mistake in the pull request. I reviewed the logic before submitting, but somehow I confused the date ranges and thought that records after the 20th day would fall into p2 instead of p1. It seems to have been an error in interpretation, possibly due to fatigue.

I’ll make sure to pay closer attention in future reviews. Thanks again for pointing this out!

Best regards,
Breno Cabral.

1 Like

No worries, thanks for reporting!

This could be something we got wrong. Even when we are technically correct it’s always great to have feedback on things that might not be that clear, and this could be one of those!