Spot the Bug answer: The loop condition i < tracks.length - 1 causes the last element of the array to be skipped.
The fix:
Change the loop condition to i < tracks.length or i <= tracks.length - 1.
Why:
Array indices are 0-based. For an array of length N, valid indices are 0 to N-1. The original condition i < tracks.length - 1 means the loop runs for i from 0 up to tracks.length - 2, effectively missing the element at index tracks.length - 1.