loading...

Discussion on: How to create range in Javascript

Collapse
teraspora profile image
John Lynch

I just use a one-liner recursive arrow function in ES6; note, it doesn't check but you should only pass it integers else it will never get to a == b so it will blow the stack!



let range = (a, b) => a>b ? range(b, a).reverse() : (a==b ? [a] : range(a, b-1).concat(b));
Collapse
ycmjason profile image
Info Comment marked as low quality/non-constructive by the community. View code of conduct
Jason Yu Author

Are you actually using this in production code? 😂😂

You realise how inefficient this is right? 😂😂

Collapse
ycmjason profile image
Jason Yu Author

I have adapted Namir's method (see comments). And it is probably the most efficient.