Range function and median function (with tests)