Skip to content

Instantly share code, notes, and snippets.

@worc
Created February 21, 2018 18:17
Show Gist options
  • Save worc/523b0c9ee7348afdfe810c1c2f8ceac5 to your computer and use it in GitHub Desktop.
Save worc/523b0c9ee7348afdfe810c1c2f8ceac5 to your computer and use it in GitHub Desktop.
Iterator over a shuffled array forever
import shuffle from './shuffle';
export default function* (list) {
let index = 0;
shuffle(list);
while (list) {
if (index >= list.length) {
shuffle(list);
index = 0;
}
yield list[index++];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment