Skip to content

Instantly share code, notes, and snippets.

@samkcarlile
Created May 4, 2022 16:16
Show Gist options
  • Save samkcarlile/b30553fb16def1e4fd17cc2146949450 to your computer and use it in GitHub Desktop.
Save samkcarlile/b30553fb16def1e4fd17cc2146949450 to your computer and use it in GitHub Desktop.
The missing `range` iterator
export function range(start: number, stop = start, step = 1) {
start = stop === start ? 0 : start;
const end = stop === start ? start : stop;
return {
*[Symbol.iterator]() {
for (let i = start; i < end; i += step) yield i;
},
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment