r/javaScriptStudyGroup • • Feb 22 '16

Python 3 range in JS

Was reading through some posts over at ES6 Discuss and came across people asking for range style functions to be in next update of JS.

Decided to give making one a go. Managed to get it shorter than I thought I would.
Gives same results as Python 3. ie.

range(5) = 0, 1, 2, 3, 4
range(1, 5) = 1, 2, 3, 4  
range(0, 10, 2) = 0, 2, 4, 6, 8

For use with for..of iterators. Uses ES6 Generators / default params
Codepen

2 Upvotes

1 comment sorted by

View all comments

2

u/ForScale Feb 25 '16

Interesting. Good stuff!