Last active
February 9, 2019 22:18
-
-
Save loraxx753/30da6ce12b3c5b62d0755e716fe1702e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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