This is probably a simple fix but when I run the loop below r1 and r2 sometimes don't fulfill the conditions to break the loop but the loop still breaks and returns the values. For example the loop breaks even if Math.abs(r1-r2)<3
let r1
let r2
do{
r1 = Math.round(Math.random()*(elementsToSwap.length-1))
r2 = Math.round(Math.random()*(elementsToSwap.length-1))
}while(
(Math.abs(r1-r2)<3)
&&prev.includes(r1)
&&prev.includes(r2)
)
What am I doing wrong?
elementsToSwap
and prev
are both arrays.
Aucun commentaire:
Enregistrer un commentaire