Last active
May 22, 2016 10:44
-
-
Save slikts/486ec32f43ed3da56179d9e2c36a2d43 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(list) { | |
const arr = [...list] | |
let i = 0 | |
for (;;) { | |
i = (i + ((yield arr[i]) || 1)) % arr.length | |
} | |
} | |
const it = cycle(['a', 'b', 'c']) | |
console.log(...[it.next(), it.next(), it.next(), it.next(), it.next(2), it.next(-1), it.next(-1)].map(x => x.value)) // a b c a c b a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment