Last active
March 20, 2019 09:15
-
-
Save Sawtaytoes/8ba6751676d51e234b43612f3451dcc9 to your computer and use it in GitHub Desktop.
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
const queue1 = [] | |
const queue2 = [] | |
let timeoutIds = {} | |
let queue = queue1 | |
const clearQueue = ( | |
queue, | |
) => { | |
queue | |
.splice( | |
0, | |
queue.length, | |
) | |
} | |
const renderNode = ( | |
id, | |
) => ( | |
setTimeout( | |
() => { | |
queue | |
.push(id) | |
}, | |
getRandomTimeout(), | |
) | |
) | |
let intervalId | |
const createInterval = () => ( | |
setInterval( | |
() => { | |
queue = ( | |
queue1.length > 0 | |
? queue2 | |
: queue1 | |
) | |
const tempQueue = ( | |
queue1.length > 0 | |
? queue1 | |
: queue2 | |
) | |
for (const id of tempQueue) { | |
const node = ( | |
document | |
.getElementById(`node-${id}`) | |
) | |
if (!node) { | |
continue | |
} | |
node.innerHTML = getRandomValue() | |
node.style.color = getRandomColor() | |
timeoutIds[id] = renderNode(id) | |
} | |
clearQueue(tempQueue) | |
}, | |
40, | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment