title: How to run multiple timers one after another with pause in javacript?
body: <p>I need to run multiple timer one after another with pause. Input for timer comes from the array which contains set of times. I did something with reduce method. But could not break early the reduce method.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const times = [5, 4, 5];
  function countDown(secs) {
          console.log(secs);
          if (secs === 1) {
              clearTimeout(timer);
              return timer;
          }
          secs--;
          var timer = setTimeout(() =&gt; countDown(secs), 1000);
  }
  
  times.reduce((totalDelay, time) =&gt; {
      setTimeout(() =&gt; {
          countDown(delay);
      }, 1000 * totalDelay);
      const delay = parseInt(time);
      totalDelay += delay;
      return totalDelay;
  }, 0);</code></pre>
  </div>
  </div>
  </p>
  <p>I tried with a boolean to pause and play. The timer is paused by that boolean variable but when I resume two timer is running because of the reduce.</p>
  <p>Is there any other way to do this with loop or something?</p>