I have been working for some time on a script that will show a matrix
with the elements aligned on the right for sometime and finally got it
to work. Then I did some patching up and ran the script and it showed a
blank page and no error in the status bar. The script is rather long
and I call functions that do things that I may not need the functiosn
for but they are there because I so that task so many times that I jsut
made it into a function. OK here is the script:
function create2darr(row s,cols) {
output = new Array(rows);
for (i=0;i<rows;i++ ) {
output[i] = new Array(cols);
}
return output;
}
function copy1darr(input ) {
output = new Array(input.len gth);
for (i=0;i<input.le ngth;i++) {
output[i] = input[i];
}
return output;
}
function copy2darr(input ) {
output = create2darr(inp ut.length,input[0].length);
for (i=0;i<input.le ngth;i++) {
for (j=0;j<input[0].length;j++) {
output[i][j] = input[i][j];
}
}
return output;
}
function findmax(input) {
Temp = copy1darr(input );
for (i=0;i<Temp.len gth;i++) {
for (j=0;j<Temp.len gth-1;j++) {
Temp[j] = Math.max(Temp[j],Temp[j+1]);
}
}
return Temp[0];
}
function show(input) {
if (input[0].length == undefined) {
document.write( "<b>[</b>");
for (i=0;i<input.le ngth-1;i++) {
document.write( input[i] + " ");
}
document.write( input[input.length-1] + "<b>]</b><br>");
} else {
S = create2darr(inp ut.length,input[0].length);
L = create2darr(S.l ength,S[0].length);
T = create2darr(S[0].length,S.lengt h);
M = new Array(S[0].length);
for (i=0;i<input.le ngth;i++) {
for (j=0;j<input[0].length;j++) {
S[i][j] = input[i][j].toString();
L[i][j] = S[i][j].length;
T[j][i] = L[i][j];
}
}
for (as=0;as<M.leng th;as++) {
M[as] = findmax(T[as]);
}
for (i=0;i<S.length ;i++) {
for (j=0;j<S[0].length;j++) {
while (S[i][j].length < 6*(M[j]-S[i][j].length)) {
S[i][j] = ' ' + S[i][j];
}
}
for (i=0;i<S.length ;i++) {
switch (i) {
case 0:
document.write( "<font face=symbol> 33;</font>");
break;
case S.length-1:
document.write( "<font face=symbol> 35;</font>");
break;
default: document.write( "<font
face=symbol> 34;</font>");
}
for (j=0;j<S[i].length-1;j++) {
document.write( S[i][j] + " ");
}
document.write( S[i][S[i].length-1]);
switch (i) {
case 0:
document.write( "<font face=symbol> 49;</font>");
break;
case S.length-1:
document.write( "<font face=symbol> 51;</font>");
break;
default: document.write( "<font
face=symbol> 39;</font>");
}
document.write( "<br>");
}
}
}
a = [
[2.33,43463, 45676786],
[334, 23, 5.3],
[ 3, 2.6, 57087]
];
show(a);
with the elements aligned on the right for sometime and finally got it
to work. Then I did some patching up and ran the script and it showed a
blank page and no error in the status bar. The script is rather long
and I call functions that do things that I may not need the functiosn
for but they are there because I so that task so many times that I jsut
made it into a function. OK here is the script:
function create2darr(row s,cols) {
output = new Array(rows);
for (i=0;i<rows;i++ ) {
output[i] = new Array(cols);
}
return output;
}
function copy1darr(input ) {
output = new Array(input.len gth);
for (i=0;i<input.le ngth;i++) {
output[i] = input[i];
}
return output;
}
function copy2darr(input ) {
output = create2darr(inp ut.length,input[0].length);
for (i=0;i<input.le ngth;i++) {
for (j=0;j<input[0].length;j++) {
output[i][j] = input[i][j];
}
}
return output;
}
function findmax(input) {
Temp = copy1darr(input );
for (i=0;i<Temp.len gth;i++) {
for (j=0;j<Temp.len gth-1;j++) {
Temp[j] = Math.max(Temp[j],Temp[j+1]);
}
}
return Temp[0];
}
function show(input) {
if (input[0].length == undefined) {
document.write( "<b>[</b>");
for (i=0;i<input.le ngth-1;i++) {
document.write( input[i] + " ");
}
document.write( input[input.length-1] + "<b>]</b><br>");
} else {
S = create2darr(inp ut.length,input[0].length);
L = create2darr(S.l ength,S[0].length);
T = create2darr(S[0].length,S.lengt h);
M = new Array(S[0].length);
for (i=0;i<input.le ngth;i++) {
for (j=0;j<input[0].length;j++) {
S[i][j] = input[i][j].toString();
L[i][j] = S[i][j].length;
T[j][i] = L[i][j];
}
}
for (as=0;as<M.leng th;as++) {
M[as] = findmax(T[as]);
}
for (i=0;i<S.length ;i++) {
for (j=0;j<S[0].length;j++) {
while (S[i][j].length < 6*(M[j]-S[i][j].length)) {
S[i][j] = ' ' + S[i][j];
}
}
for (i=0;i<S.length ;i++) {
switch (i) {
case 0:
document.write( "<font face=symbol> 33;</font>");
break;
case S.length-1:
document.write( "<font face=symbol> 35;</font>");
break;
default: document.write( "<font
face=symbol> 34;</font>");
}
for (j=0;j<S[i].length-1;j++) {
document.write( S[i][j] + " ");
}
document.write( S[i][S[i].length-1]);
switch (i) {
case 0:
document.write( "<font face=symbol> 49;</font>");
break;
case S.length-1:
document.write( "<font face=symbol> 51;</font>");
break;
default: document.write( "<font
face=symbol> 39;</font>");
}
document.write( "<br>");
}
}
}
a = [
[2.33,43463, 45676786],
[334, 23, 5.3],
[ 3, 2.6, 57087]
];
show(a);
Comment