It’s correct, though I could make it less clear with algebra, making +2 or -2 on one side or the other. The index of interest is index + 1, to check whether the index of interest is in the last position is offsets.length - 1, but < offsets.length would do the job.