Skip to content

Instantly share code, notes, and snippets.

@joelbarbosa
Created March 11, 2020 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelbarbosa/6b025645509c117d19b35b22384575f1 to your computer and use it in GitHub Desktop.
Save joelbarbosa/6b025645509c117d19b35b22384575f1 to your computer and use it in GitHub Desktop.
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