Last active
November 11, 2016 22:51
-
-
Save tildebyte/82cc5f284417d6e765f5be41dbc3cc3d to your computer and use it in GitHub Desktop.
Damn good JS implementation of Python's `range`, using ES6 Generator.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let range = function * (start = 0, end = null, step = 1) { | |
if (end === null) { | |
end = start | |
start = 0 | |
} | |
let value = start | |
while (value < end || end < value) { | |
yield value | |
value += step | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on several partly-working ideas from SO
http://stackoverflow.com/questions/8273047/javascript-function-similar-to-python-range
http://stackoverflow.com/questions/3895478/does-javascript-have-a-method-like-range-to-generate-an-array-based-on-suppl