This question already has an answer here:
- Golfing the Core 8 answers
You have to create a function range
, such that it takes two (integer) arguments a
and b
(a < b
) and returns all the numbers in between them. So:
range(5, 10) // should output 6, 7, 8, 9
range(-5, 2) // should output -4, -3, -2, -1, 0, 1
range(5, 0) // can throw an error/empty/null/undefined/whatever (a is not < b)
// bonus points for non integer handling
range(0.5, 4.5) // 1.5, 2.5, 3.5
range(0.5, 4) // range doesn't make sense, error/null/empty
range(5, 5) // etc. should return empty/null/undefined/whatever
Your code must not use any numbers at all, but you can use arithmetic operators. If your language has a range
function in-built, you cannot use that as well.
Shortest code wins.