I would also cache the array's `length` since it is accessed three times.