Skip to content

Instantly share code, notes, and snippets.

@kanian
Created May 21, 2019 16:46
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 kanian/955387ac3101bf4f9ee3dc024df2591b to your computer and use it in GitHub Desktop.
Save kanian/955387ac3101bf4f9ee3dc024df2591b to your computer and use it in GitHub Desktop.
function cycle(...args){
let [x,y] = [...args]
let els = Array.isArray(x) ? x : typeof y === 'undefined' ? [x] : [...filler(x,y)]
let index = 0
return {
[Symbol.iterator]: function* (){
let _n = 0
while ( _n < els.length){
yield els[_n]
_n++
}
},
next: function() {
if(index === els.length) // cycle
index = 0
return {value: els[index++], done: false}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment