Skip to content

Instantly share code, notes, and snippets.

@togakangaroo
Created March 9, 2017 03:50
Show Gist options
  • Save togakangaroo/1e45238a553d26f969854eba9b4d02b3 to your computer and use it in GitHub Desktop.
Save togakangaroo/1e45238a553d26f969854eba9b4d02b3 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