Skip to content

Instantly share code, notes, and snippets.

@togakangaroo
Created March 9, 2017 03:52
Show Gist options
  • Save togakangaroo/f9e984318de947a48d4a1e802acd3a0d to your computer and use it in GitHub Desktop.
Save togakangaroo/f9e984318de947a48d4a1e802acd3a0d to your computer and use it in GitHub Desktop.
var createCounter = (startVal = 0) => {
let state = startVal
return {
next: () => {
if(state < (10 + startVal))
return {value: state+=1}
return {done: true}
}
}
}
var counter = createCounter(5)
var {done, value} = counter.next()
while(!done) {
console.log(value)
const x = counter.next()
done = x.done
value = x.value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment