Created
May 29, 2016 14:07
-
-
Save erikthedeveloper/3a5de7fc8ba2606340bfc84e4c006cc2 to your computer and use it in GitHub Desktop.
A little Javascript challenge
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
| /** | |
| * Given an array of "steps", execute them while accounting for delay | |
| * See: https://medium.com/@kitze/js-coding-challenge-1-test-your-skills-63c2af5446d0#.n2wq6jyqu | |
| * @param {function|int[]} steps | |
| */ | |
| const sequence = (steps) => steps.reduce( | |
| // Reduce the steps, keeping track of an accumulated timeout | |
| (timeout, step) => typeof step === 'function' | |
| // Yes: invoke it with the currently accumulated timeout | |
| ? setTimeout(step, timeout) && timeout | |
| // No: it is an integer. Increase accumulated timeout | |
| : timeout + step | |
| , 0); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
JSBin link here: http://jsbin.com/maqopig/edit?js,console