Skip to content

Instantly share code, notes, and snippets.

@bishil06
Created February 9, 2021 02:21
Show Gist options
  • Save bishil06/67b3a9512ba3f17fd814753d7f150dbd to your computer and use it in GitHub Desktop.
Save bishil06/67b3a9512ba3f17fd814753d7f150dbd to your computer and use it in GitHub Desktop.
_JavaScript_range_iterable
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