Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. Rearranging and displaying arrays

Hello,

I'm trying to take a 2D array of user input display it, rearrange it, and display it again according to Mathew's Algorithm.

The matrices would like this:

ORIGINAL-
[0][0], [0][1], [0][2], [0][3],
[1][0], [1][1], [1][2], [1][3],
[2][0], [2][1], [2][2], [2][3],
[3][0], [3][1], [3][2], [3][3]

REARRANGED
[0][0], [1][1], [2][2], [3][3],
[3][0], [0][1], [1][2], [2][3],
[2][0], [3][1], [0][2], [1][3],
[1][0], [2][1], [3][2], [0][3]

As it is now entering the input and displaying the first table is no problem. After that, though, something goes wrong. The second table does not display, I don't know if the problem is the algorithmRot() function or the tableMaker()

Here are both of those funtions (I would be happy to provide the whole code if necessary, just trying to be concise)

Code:
```/****A 2d of information is passed to tableMaker() which displays the
matrix, and than passes it up to algorithmRot() which rearranges its pieces
and passes it back.*****/

function algorithmRot(x){
var xRef = [];
for(i=0; i<x.length; i++){
for(j=0; j<x.length; j++){
xRef[i][j]=j;
}}

for(i=0; i<x.length; i++){
var a=xRef[i].splice(-i);
a.reverse()
for(j=0; j<a.length; j++){
xRef[i].splice(0,0,a[j]);// OR TRY unshift(a[j]);
}}

for(i=0; i<x.length; i++){
for(j=0; j<x.length; j++){
x[i][j]=x[xRef[i][j]][j];
}}

}

function tableMaker(x){
var table = [];
var row = [];
var col = [];
var div = document.getElementById("cont");

for(i=0; i<x.length; i++){
table[i] = document.createElement("table");
row[i] = document.createElement("tr");

for(j=0; j<x.length; j++){

col[j] = document.createElement("td");
table[i].appendChild(row[i]);
div.appendChild(table[i]);
}

algorithmRot(x);

/*****2ND TABLE*******/

for(i=0; i<x.length; i++){
table[i] = document.createElement("table");
row[i] = document.createElement("tr");

for(j=0; j<x.length; j++){

col[j] = document.createElement("td");
table[i].appendChild(row[i]);
div.appendChild(table[i]);
}

}```
any help will be greatly appreciated as I've knocking my skull against a wall on this one for a while.

• Troubleshoot stuff like this by a) examining the error console in Firefox (I'm assuming you use Firefox as you are a developer), and b) inserting alert() messages in strategic locations so you can trace through the values of the arrays to figure out what is actually happening.

• Users who have thanked Fumigator for this post:

bnagle (08-30-2007)

• thanks

thanks for the reply, I have one quick question though, is the error console you mentioned the same as the venkman debugger? If not where on the browser would I find that guy?

thanks again,