Skip to content

Instantly share code, notes, and snippets.

@kitze
Last active November 23, 2018 16:10
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kitze/6291dab229c909aefabb5b3141000f37 to your computer and use it in GitHub Desktop.
Save kitze/6291dab229c909aefabb5b3141000f37 to your computer and use it in GitHub Desktop.
Solution
/*
* If the loop bumps into an function, it returns true, and moves on,
* but if it bumps into a number, it waits x milliseconds,
* it stops the _.every loop by returning false, and recursively
* calls the sequence function with the rest of the array.
* Nifty, huh? 😝😝
*/
const sequence = b => b.every((a, i) => !(a.call ? a() : setTimeout(() => sequence(b.slice(++i)), a)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment