Pages

mélanger un tableau ?

const s = "123456789"; //string


const t = Array.from(s,s => Number(s)); //String transform tab 

// Array.from({length: 9}, (v, k) => k);   

function shuffle(t){

  for (let i=t.length-1 ; i > 1 ; i--){

     let nb = Math.floor(Math.random() * i);

  //swap

    [t[nb],t[i]] =     [t[i],t[nb]] 

   }

}
while (t[0]< 8){
  shuffle(t);
  console.log(t);

}