Skip to content

Instantly share code, notes, and snippets.

@GitSquared
Last active June 9, 2018 14:04
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 GitSquared/9c5c9fe5985a14c35e2773fc9a96ade8 to your computer and use it in GitHub Desktop.
Save GitSquared/9c5c9fe5985a14c35e2773fc9a96ade8 to your computer and use it in GitHub Desktop.
console.log("START");
let i = 0;
let left = ["left_one", "left_two", "left_three", "left_four"];
let right = ["right_one", "right_two"];
let x = setInterval(() => {
if (!left[i] && !right[i]) {
console.log("DONE!");
clearInterval(x);
} else {
console.log(`RUN ${i}: ${(i+1)*500}MS`);
if (left[i]) {
console.log("-> Display", left[i]);
}
if (right[i]) {
console.log("-> Display", right[i]);
}
i++;
}
}, 500);
// Expected output:
// START
// RUN 0: 500MS
// -> Display left_one
// -> Display right_one
// RUN 1: 1000MS
// -> Display left_two
// -> Display right_two
// RUN 2: 1500MS
// -> Display left_three
// RUN 3: 2000MS
// -> Display left_four
// DONE!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment