Skip to content

Instantly share code, notes, and snippets.

@loraxx753
Last active February 9, 2019 22:18
Show Gist options
  • Save loraxx753/30da6ce12b3c5b62d0755e716fe1702e to your computer and use it in GitHub Desktop.
Save loraxx753/30da6ce12b3c5b62d0755e716fe1702e to your computer and use it in GitHub Desktop.
const data = [
[1,2,3,4,5],
[6,7,8,9,10]
]
function* getNumbers() {
for(let idx in data) {
for(let subIdx in data[idx]) {
yield data[idx][subIdx]
}
}
}
const getNumber = getNumbers()
(function() {
const aNumber = getNumber.next().value // getNumber().next() gives { value: 1, done: false }
const anotherNumber = getNumber.next().value
const yetAnotherNumber = getNumber.next().value
console.log(aNumber, anotherNumber, yetAnotherNumber) // 1, 2, 3
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment