Created
February 22, 2019 18:20
-
-
Save mattdeboard/3bd8294024f0c00bca4ffcc7b997218a to your computer and use it in GitHub Desktop.
Cycle through data infinitely. Optionally specify a starting index.
This file contains hidden or 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* cycleFrom(elements, startIndex = 0) { | |
let index = startIndex; | |
while (true) { | |
if (index >= elements.length) { | |
index = index % elements.length; | |
} | |
yield elements[index]; | |
index += 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment