Sign up ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

This question already has an answer here:

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.

share|improve this question

marked as duplicate by Martin Büttner code-golf Jan 24 at 22:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2  
Even if I was writing this in normal code without constraints, I doubt I would have any reason to use numeric literals. – feersum Jan 24 at 21:52
    
Hello, and welcome to PPCG. "bonus points for non integer handling" is not specific enough for this site. You should either define absolute measures (e.g. -10 bytes) or remove this part from your question. – FryAmTheEggman Jan 24 at 21:54
    
I decided to close this as a duplicate, as the source restriction seems irrelevant (as feersum said). Of course, the other challenge required to implement the step width as well, but that seems like a trivial thing to change. Of course, anyone who disagrees is welcome to cast reopen votes. – Martin Büttner Jan 24 at 22:04

1 Answer 1

Javascript (49)(45)

As feersum said, I do not know why anyone would have to use numbers here.

f=(a,b)=>{for(c=[];a<b;c.push(a++));return c}

Old:

f=(a,b)=>{c=[];for(;a<b;a++){c.push(a);}return c}

I am sure it can be golfed down further=)

share|improve this answer
1  
I believe it has to be named range – FryAmTheEggman Jan 24 at 21:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.