Could you rewrite this using the ternary operator and also so that if the distance variable is out of range it returns -1?