<HTML>
<body>
</body>
<script>
let arr = [1,2,3];
function shuffle(array){
array.sort(() => Math.random() - 0.5);
//since math.random() returns a number between 0 and 1
//by - 0.5, it can be a negative or positive
//and the sorting function compares
//each element by that randomly generated returned value
}
shuffle(arr);
alert(arr);
shuffle(arr);
alert(arr);
shuffle(arr);
alert(arr);
</script>
</HTML>
<body>
</body>
<script>
let arr = [1,2,3];
function shuffle(array){
array.sort(() => Math.random() - 0.5);
//since math.random() returns a number between 0 and 1
//by - 0.5, it can be a negative or positive
//and the sorting function compares
//each element by that randomly generated returned value
}
shuffle(arr);
alert(arr);
shuffle(arr);
alert(arr);
shuffle(arr);
alert(arr);
</script>
</HTML>
댓글
댓글 쓰기