Most racing games use checkpoints: a simple set of sprites (visible or not) along the way that you have to drive through to be permitted to cross the finish line.
My suggestion would be to use a one-dimensional array that is as long along the x-axis as there are checkpoints (and this can be dynamically assigned at the start of each race by counting the checkpoints). As the player passes each checkpoint, add 1 to the cell in the array determined by the checkpoint's IID.
When the player crosses the finish line, check if the combined total across the array matches the number of checkpoints in the track. Clear the array after crossing the finish line and add one to the number of laps in a variable.