Choosing of perso now not so random
This commit is contained in:
@ -129,7 +129,6 @@ async function base() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
outerListFinal.push(innerListFinal)
|
outerListFinal.push(innerListFinal)
|
||||||
// console.log(listB)
|
|
||||||
return outerListFinal
|
return outerListFinal
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,24 +170,33 @@ app.get('/', async (_, res) => {
|
|||||||
</div>
|
</div>
|
||||||
{<script dangerouslySetInnerHTML={{__html:`
|
{<script dangerouslySetInnerHTML={{__html:`
|
||||||
let intervalIds = [];
|
let intervalIds = [];
|
||||||
|
let listToRandom = [0, 1, 2, 3, 4, 5]
|
||||||
|
let countPerso = 0;
|
||||||
fetch('http://localhost:3000/code')
|
fetch('http://localhost:3000/code')
|
||||||
.then(function(response) {
|
.then(function(response) {
|
||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
|
let notSoRandomList = []
|
||||||
function runIntervals() {
|
function runIntervals() {
|
||||||
intervalIds.forEach(clearInterval);
|
intervalIds.forEach(clearInterval);
|
||||||
intervalIds = [];
|
intervalIds = [];
|
||||||
let timeOuter = 5000;
|
let timeOuter = 3000;
|
||||||
let timeInner = 1000;
|
let timeInner = 500;
|
||||||
let countAnim = 1;
|
let countAnim = 1;
|
||||||
let minPerso = 0;
|
if(countPerso === 6){
|
||||||
let maxPerso = 5;
|
countPerso = 0
|
||||||
let perso = Math.floor(Math.random() * (maxPerso - minPerso + 1) + minPerso);
|
}
|
||||||
|
if(countPerso === 0){
|
||||||
|
notSoRandomList = notSoRandomPerso()
|
||||||
|
}
|
||||||
|
let perso = notSoRandomList[countPerso]
|
||||||
|
|
||||||
let length = data[perso].length
|
let length = data[perso].length
|
||||||
if(length*timeInner > timeOuter){
|
if(length*timeInner > timeOuter){
|
||||||
timeOuter = length*timeInner + timeInner
|
timeOuter = length*timeInner + timeInner
|
||||||
}
|
}
|
||||||
|
countPerso = countPerso + 1;
|
||||||
let imgElement = document.getElementById(perso);
|
let imgElement = document.getElementById(perso);
|
||||||
if (imgElement){
|
if (imgElement){
|
||||||
intervalIds.push(setInterval(function() {
|
intervalIds.push(setInterval(function() {
|
||||||
@ -208,6 +216,14 @@ app.get('/', async (_, res) => {
|
|||||||
}, timeOuter);
|
}, 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() {
|
function stopIntervals() {
|
||||||
intervalIds.forEach(clearInterval);
|
intervalIds.forEach(clearInterval);
|
||||||
intervalIds = [];
|
intervalIds = [];
|
||||||
|
32
test.js
32
test.js
@ -1,18 +1,32 @@
|
|||||||
let intervalIds = [];
|
let intervalIds = [];
|
||||||
|
let listToRandom = [0, 1, 2, 3, 4, 5]
|
||||||
|
let countPerso = 0;
|
||||||
|
console.log('ouaip')
|
||||||
fetch('http://localhost:3000/code')
|
fetch('http://localhost:3000/code')
|
||||||
.then(function(response) {
|
.then(function(response) {
|
||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
|
let notSoRandomList = []
|
||||||
function runIntervals() {
|
function runIntervals() {
|
||||||
intervalIds.forEach(clearInterval);
|
intervalIds.forEach(clearInterval);
|
||||||
intervalIds = [];
|
intervalIds = [];
|
||||||
let timeOuter = 5000;
|
let timeOuter = 3000;
|
||||||
let timeInner = 1000;
|
let timeInner = 500;
|
||||||
let countAnim = 1;
|
let countAnim = 1;
|
||||||
let minPerso = 0;
|
if(countPerso === 5){
|
||||||
let maxPerso = 5;
|
countPerso = 0
|
||||||
let perso = Math.floor(Math.random() * (maxPerso - minPerso + 1) + minPerso);
|
|
||||||
|
}
|
||||||
|
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
|
let length = data[perso].length
|
||||||
if(length*timeInner > timeOuter){
|
if(length*timeInner > timeOuter){
|
||||||
timeOuter = length*timeInner + timeInner
|
timeOuter = length*timeInner + timeInner
|
||||||
@ -36,6 +50,14 @@ fetch('http://localhost:3000/code')
|
|||||||
}, timeOuter);
|
}, 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() {
|
function stopIntervals() {
|
||||||
intervalIds.forEach(clearInterval);
|
intervalIds.forEach(clearInterval);
|
||||||
intervalIds = [];
|
intervalIds = [];
|
||||||
|
Reference in New Issue
Block a user