Returns true if the given index is valid (between 0 and length - 1).
true
index
0
length - 1
bool inRange(int index) => index >= 0 && index < length;