Skip to content

Instantly share code, notes, and snippets.

@pachacamac
Forked from kitze/one-liner-solution.js
Created June 10, 2016 16:36
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 pachacamac/6af1ab033327307368f17c3cdf5fcb44 to your computer and use it in GitHub Desktop.
Save pachacamac/6af1ab033327307368f17c3cdf5fcb44 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