Skip to content

Instantly share code, notes, and snippets.

@kanian
Created May 21, 2019 15:19
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/9785d6b55210c5cee7b05c289db857b6 to your computer and use it in GitHub Desktop.
Save kanian/9785d6b55210c5cee7b05c289db857b6 to your computer and use it in GitHub Desktop.
function cycle(xs) {
let els = Array.isArray(xs) ? xs : [xs];
let index = 0;
return {
next: function() {
if (index === els.length)
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