I have table with images with 4 cols and 2 rows. I shuffle the table using this code:
function sortTable() {
//get the parent table for convenience
let table = document.getElementById("imgTable");
//1. get all rows
let rowsCollection = table.querySelectorAll("td");
//2. convert to array
let rows = Array.from(rowsCollection)
//3. shuffle
shuffleArray(rows);
//4. add back to the DOM
for (const row of rows) {
table.appendChild(row);
}
}
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
But after shuffle, everything gets into 1 row and 8 cols. How do i keep the dimension same?