From e8d59129a0861b7e9455fa2ca7af6ac8853be467 Mon Sep 17 00:00:00 2001 From: Adrien Nunes <adrien.nunes@ensiie.fr> Date: Thu, 6 Jan 2022 02:44:26 +0100 Subject: [PATCH] Infocovid random sign --- commands/CommandInfoCovid.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/commands/CommandInfoCovid.js b/commands/CommandInfoCovid.js index ca1915d..1109bcd 100644 --- a/commands/CommandInfoCovid.js +++ b/commands/CommandInfoCovid.js @@ -15,10 +15,15 @@ class CommandInfoCovid{ return Math.floor(Math.random()*(y-x) +x) } + replaceRandomIntString(str, min, max){ return str.replaceAll('<random_int>', ()=>this.getRandomInt(min,max)); } + replaceAllSign(str){ + return str.replaceAll('<signe>', ()=>{ return Math.floor(Math.random()*2)? '+' : '-'}); + } + replaceSmallRandomIntString(str){ const smallRandom = this.getRandomInt(1,5); const plur = (smallRandom > 1) ? 's' : ''; @@ -40,7 +45,7 @@ class CommandInfoCovid{ getRandomAction(){ const action = this.actions[Math.floor(Math.random()*this.actions.length)]; - return this.replaceRandomIntString(this.replaceSmallRandomIntString(action), 1, 24); + return this.replaceAllSign(this.replaceRandomIntString(this.replaceSmallRandomIntString(action), 1, 24)); } getRandomTemps(){ -- GitLab