CoddityTeam / movaicode

Concours mensuel du Pire Développeur de France
123 stars 10 forks source link

Random Wait13 Generator #249

Open Anthony-Coddity opened 1 year ago

Anthony-Coddity commented 1 year ago

Parce que pourquoi pas.

const sleep = (value) => new Promise(r => setTimeout(r, value));

const getRandomInt = (min, max) => {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min + 1) + min);
}

const wait13 = async () => {
  let seconde = 13000;
  while (seconde > 0) {
    const secondeToWait1 = getRandomInt(1, seconde);
    const secondeToWait2 = getRandomInt(1, seconde);
    var secondeToWaitChoice = secondeToWait1 > secondeToWait2 ? secondeToWait2 : secondeToWait1;
    await sleep(secondeToWaitChoice);
    seconde -= secondeToWaitChoice;
  }
};

wait13();

On pourra plus me dire que j'ai rien fait