Created
December 26, 2016 22:19
-
-
Save mhingston/488cd5391e17095290e96bbdd8f385a4 to your computer and use it in GitHub Desktop.
Python's xrange() for javascript
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
function* xrange(start, stop, step) | |
{ | |
if(stop === undefined) | |
{ | |
stop = start; | |
start = 0; | |
} | |
if(step === undefined) | |
{ | |
step = 1; | |
} | |
for(let i=start; start < stop ? i < stop : i > stop; i += step) | |
{ | |
yield i; | |
} | |
} | |
// Usage example: | |
//for (const i of xrange(10)) | |
//{ | |
// console.log(i); | |
//} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment