Wednesday, January 18, 2023

Problem: Fill array by dice numbers; all different 2

function gapLot(){
  
  var array6=[];
  var array2=[1,2,3,4,5,6];
  var random;
 
    for(var i=0;i<6;i++){ //0-5
      random= Math.floor(Math.random() * (6-i))+1;

        if(random==(6-i)){
   
          array6[i]=array2[5-i];
 
        }else{

  
         array6[i]=array2[random-1];
 
         array2[random-1]=array2[5-i];

  
       }
  }
  
   return array6;
 }
 console.log(gapLot());


No comments:

Post a Comment

3D BLog has return

Go  to Check    https://thereal3dblog.com/