Created
May 4, 2022 16:16
-
-
Save samkcarlile/b30553fb16def1e4fd17cc2146949450 to your computer and use it in GitHub Desktop.
The missing `range` iterator
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
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