Created
March 13, 2021 12:49
-
-
Save NovoManu/302c5ab9097567f3ee6ddd7fb40aa0f7 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* generateSequence(start, end) { | |
for (let i = start; i <= end; i++) yield i | |
} | |
const sequence1 = generateSequence(1, 10) | |
for (const n of sequence1) { | |
console.log(n) // Expected output: sequence from 1 to 10 | |
} | |
const sequence2 = generateSequence(1, 3) | |
console.log(sequence2.next().value) // Expected output: 1 | |
console.log(sequence2.next().value) // Expected output: 2 | |
console.log(sequence2.next().value) // Expected output: 3 | |
console.log(sequence2.next().done) // Expected output: true | |
const abcCodes = generateSequence(65, 90) | |
for (const code of abcCodes) { | |
console.log(String.fromCharCode(code)) // Expected output: ABC from A to Z | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment