Skip to content

Instantly share code, notes, and snippets.

@MVAodhan
Last active September 6, 2022 06:36
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 MVAodhan/ad2dfc06f7a7ffbf1d8a3e4393e4634e to your computer and use it in GitHub Desktop.
Save MVAodhan/ad2dfc06f7a7ffbf1d8a3e4393e4634e to your computer and use it in GitHub Desktop.
function* fromTo(x, y) {
for (let i = x; i <= y; i++) {
yield i;
}
}
let fn = fromTo(5, 7);
let fnA = [...fn];
const gen=()=>{
console.log(fnA)
let toReturn = fnA[0]
fnA.shift()
return toReturn;
}
gen() // 5
gen() //6
gen() //7
gen() // undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment