cache the length of the array with the use of `max`