Created
January 26, 2021 08:53
-
-
Save FelixLuciano/0ed35078696d99997ab20fbbf40f71f4 to your computer and use it in GitHub Desktop.
Javascript implementation of Python's range
This file contains 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* range(start, stop, step = 1) { | |
if (stop === undefined) stop = start, start = 0; | |
for (let i = start; step > 0 ? i < stop : step < 0 ? i > stop : false; i += step) yield i; | |
} | |
// for (let index of range(0, 10, 1) | |
// Array.from(range(0, 10, 1)) | |
// or | |
// [...range(0, 10, 1)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment