JSFiddle - React, Tailwind, and code Playground

by Doeke Wartena

JavaScript

$(function() {
	
  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

  var switch_on = function(time_outs, index) {

    if (index == undefined) {
      switch_on(time_outs, 0);
      return;
    }
		
    console.log("do stuff");

    
    // recursive call the method again if required
    if (index < time_outs.length - 1) {
      var time_out = time_outs[index];
      console.log("time_out: "+time_out);
      setTimeout(switch_on($target, time_outs, index + 1), time_out);
    }

  };

  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  
  var time_outs = [1001, 1002, 1003, 1004, 1005];
  
  switch_on(time_outs);

  console.log("done");

});