JavaScript
nodejs

Light red and blue alternately

const timer = require('timers')

const lightList = ['red', 'blue']

const LIGHT = {};
const lights = 'lights';

for (const light of lightList) {
  LIGHT[light] = `${lights} ${light}`
}

const lightAnyColor = ({light, nextLightFunc, lightTime}) => {
  timer.setTimeout(() => {
    console.log(light)
    nextLightFunc();
  }, lightTime);
}

const lightBlue = () => {
  lightAnyColor({
    light: LIGHT.blue,
    nextLightFunc: lightRed,
    lightTime: 1000,
  })
}

const lightRed = () => {
  lightAnyColor({
    light: LIGHT.red,
    nextLightFunc: lightBlue,
    lightTime: 1000,
  })
}
const start = () => {
  lightRed();
}

start();