Last active
May 21, 2019 14:35
-
-
Save kanian/ad63117bdbb848b111abb8b792a44761 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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