79124042

Date: 2024-10-25 01:59:02
Score: 0.5
Natty:
Report link

The problem seems to be with how you're handling the indexes during the iteration over the attendance collection. The index you get with the foreach loop corresponds to the position of the element in the original collection, not necessarily reflecting the order you'd expect after sorting.

The solution you can apply is to reassign the indexes after sorting, so they reflect the new position of each attendance. Here’s a simple fix for you:

After grouping and sorting the attendances, reassign the indexes to the resulting collection. Make sure the indexes reflect the new order, whether it's sorted by earliest or latest.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: Angel