Created
February 21, 2018 18:17
-
-
Save worc/523b0c9ee7348afdfe810c1c2f8ceac5 to your computer and use it in GitHub Desktop.
Iterator over a shuffled array forever
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
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