Created
February 9, 2021 02:21
-
-
Save bishil06/67b3a9512ba3f17fd814753d7f150dbd to your computer and use it in GitHub Desktop.
_JavaScript_range_iterable
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 *range(start=0, stop, step=1) { | |
while(start < stop) { | |
yield start; | |
start+=step; | |
} | |
} | |
console.log(...range(0, 5)); // 0 1 2 3 4 | |
console.log(...range(0, 10, 2)); // 0 2 4 6 8 | |
console.log(...range(1, 20, 3)); // 1 4 7 10 13 16 19 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment