Skip to content

Instantly share code, notes, and snippets.

@kanian
Last active May 21, 2019 14:35
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/ad63117bdbb848b111abb8b792a44761 to your computer and use it in GitHub Desktop.
Save kanian/ad63117bdbb848b111abb8b792a44761 to your computer and use it in GitHub Desktop.
function cycle(xs){
let els = xs
let index = 0
return {
next: function() {
if(index === els.length) // cycle
index = 0
return {value: els[index++], done: false}
}
}
}
function take(n,xs){
let it = xs
let taken = []
let nxt
while(n > 0){
if((nxt = it.next()).done)
return taken
taken.push(nxt.value)
n--
}
return taken
}
function repeatPattern2(xs,n){
let times = xs.length * n
return take(times,cycle(xs))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment