Created
January 30, 2023 15:43
-
-
Save tolotrasmile/ce192b6b842c00a4c0b22f2334eb0756 to your computer and use it in GitHub Desktop.
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
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