Created
March 11, 2020 10:13
-
-
Save joelbarbosa/6b025645509c117d19b35b22384575f1 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 makeInterable = (array) => { | |
let nextIndex = 0; | |
return { | |
next: () => { | |
if (nextIndex < array.length) { | |
return {value: array[nextIndex ++], done: false} | |
} else { | |
return {done: true}; | |
} | |
} | |
} | |
} | |
const it = makeInterable(['Dayana', 'Joel', 'Lola']); | |
console.log(it.next().value) | |
console.log(it.next().value) | |
console.log(it.next().done) | |
console.log(it.next().done) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment