Skip to content

Instantly share code, notes, and snippets.

@tolotrasmile
Created January 30, 2023 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tolotrasmile/ce192b6b842c00a4c0b22f2334eb0756 to your computer and use it in GitHub Desktop.
Save tolotrasmile/ce192b6b842c00a4c0b22f2334eb0756 to your computer and use it in GitHub Desktop.
function range(start: number, end: number, step = 1) {
return {
[Symbol.iterator]() {
return this
},
next() {
if (start < end) {
start = start + step
return {
value: start,
end: false
}
}
return {
value: end,
end: true
}
}
}
}
// Example
for (let i of range(1, 20)) {
console.log(i)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment