Basically, check that start is less than length before trying to take a slice. Also, rename valueToArrayIndex to valueToRangeIndex to reflect the fact that it does not always return a value that is valid index (value could be length)