Choosing of perso now not so random

This commit is contained in:
2023-02-23 10:58:08 +01:00
parent 777d9db78e
commit b43b661606
2 changed files with 49 additions and 11 deletions

View File

@ -129,7 +129,6 @@ async function base() {
}
}
outerListFinal.push(innerListFinal)
// console.log(listB)
return outerListFinal
}
@ -171,24 +170,33 @@ app.get('/', async (_, res) => {
</div>
{<script dangerouslySetInnerHTML={{__html:`
let intervalIds = [];
let listToRandom = [0, 1, 2, 3, 4, 5]
let countPerso = 0;
fetch('http://localhost:3000/code')
.then(function(response) {
return response.json();
})
.then(function(data) {
let notSoRandomList = []
function runIntervals() {
intervalIds.forEach(clearInterval);
intervalIds = [];
let timeOuter = 5000;
let timeInner = 1000;
let timeOuter = 3000;
let timeInner = 500;
let countAnim = 1;
let minPerso = 0;
let maxPerso = 5;
let perso = Math.floor(Math.random() * (maxPerso - minPerso + 1) + minPerso);
if(countPerso === 6){
countPerso = 0
}
if(countPerso === 0){
notSoRandomList = notSoRandomPerso()
}
let perso = notSoRandomList[countPerso]
let length = data[perso].length
if(length*timeInner > timeOuter){
timeOuter = length*timeInner + timeInner
}
countPerso = countPerso + 1;
let imgElement = document.getElementById(perso);
if (imgElement){
intervalIds.push(setInterval(function() {
@ -208,6 +216,14 @@ app.get('/', async (_, res) => {
}, timeOuter);
}
}
function notSoRandomPerso(){
for (let i = listToRandom.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[listToRandom[i], listToRandom[j]] = [listToRandom[j], listToRandom[i]];
}
console.log(listToRandom)
return listToRandom
}
function stopIntervals() {
intervalIds.forEach(clearInterval);
intervalIds = [];

32
test.js
View File

@ -1,18 +1,32 @@
let intervalIds = [];
let listToRandom = [0, 1, 2, 3, 4, 5]
let countPerso = 0;
console.log('ouaip')
fetch('http://localhost:3000/code')
.then(function(response) {
return response.json();
})
.then(function(data) {
let notSoRandomList = []
function runIntervals() {
intervalIds.forEach(clearInterval);
intervalIds = [];
let timeOuter = 5000;
let timeInner = 1000;
let timeOuter = 3000;
let timeInner = 500;
let countAnim = 1;
let minPerso = 0;
let maxPerso = 5;
let perso = Math.floor(Math.random() * (maxPerso - minPerso + 1) + minPerso);
if(countPerso === 5){
countPerso = 0
}
if(countPerso === 0){
notSoRandomList = notSoRandomPerso()
}
let perso = notSoRandomList[countPerso]
countPerso = countPerso + 1;
// let minPerso = 0;
// let maxPerso = 5;
// let perso = Math.floor(Math.random() * (maxPerso - minPerso + 1) + minPerso);
let length = data[perso].length
if(length*timeInner > timeOuter){
timeOuter = length*timeInner + timeInner
@ -36,6 +50,14 @@ fetch('http://localhost:3000/code')
}, timeOuter);
}
}
function notSoRandomPerso(){
for (let i = listToRandom.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[listToRandom[i], listToRandom[j]] = [listToRandom[j], listToRandom[i]];
}
console.log(listToRandom)
return listToRandom
}
function stopIntervals() {
intervalIds.forEach(clearInterval);
intervalIds = [];