# Implement range function without using numbers in code [duplicate]

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.

## marked as duplicate by Martin Ender code-golf StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Jan 24 '15 at 22:03

• 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 '15 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 '15 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 Ender Jan 24 '15 at 22:04
• For me it is not a duplicate; yes one can prefer range has its extremes instead of esclude them so 1..4 is 1 2 3 4 – RosLuP Nov 10 '18 at 20:04

# 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=)

• I believe it has to be named range – FryAmTheEggman Jan 24 '15 at 21:59