G
greenflame
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(rows,cols) {
output = new Array(rows);
for (i=0;i<rows;i++) {
output = new Array(cols);
}
return output;
}
function copy1darr(input) {
output = new Array(input.length);
for (i=0;i<input.length;i++) {
output = input;
}
return output;
}
function copy2darr(input) {
output = create2darr(input.length,input[0].length);
for (i=0;i<input.length;i++) {
for (j=0;j<input[0].length;j++) {
output[j] = input[j];
}
}
return output;
}
function findmax(input) {
Temp = copy1darr(input);
for (i=0;i<Temp.length;i++) {
for (j=0;j<Temp.length-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.length-1;i++) {
document.write(input + " ");
}
document.write(input[input.length-1] + "<b>]</b><br>");
} else {
S = create2darr(input.length,input[0].length);
L = create2darr(S.length,S[0].length);
T = create2darr(S[0].length,S.length);
M = new Array(S[0].length);
for (i=0;i<input.length;i++) {
for (j=0;j<input[0].length;j++) {
S[j] = input[j].toString();
L[j] = S[j].length;
T[j] = L[j];
}
}
for (as=0;as<M.length;as++) {
M[as] = findmax(T[as]);
}
for (i=0;i<S.length;i++) {
for (j=0;j<S[0].length;j++) {
while (S[j].length < 6*(M[j]-S[j].length)) {
S[j] = ' ' + S[j];
}
}
for (i=0;i<S.length;i++) {
switch (i) {
case 0:
document.write("<font face=symbol>é</font>");
break;
case S.length-1:
document.write("<font face=symbol>ë</font>");
break;
default: document.write("<font
face=symbol>ê</font>");
}
for (j=0;j<S.length-1;j++) {
document.write(S[j] + " ");
}
document.write(S[S.length-1]);
switch (i) {
case 0:
document.write("<font face=symbol>ù</font>");
break;
case S.length-1:
document.write("<font face=symbol>û</font>");
break;
default: document.write("<font
face=symbol>ï</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(rows,cols) {
output = new Array(rows);
for (i=0;i<rows;i++) {
output = new Array(cols);
}
return output;
}
function copy1darr(input) {
output = new Array(input.length);
for (i=0;i<input.length;i++) {
output = input;
}
return output;
}
function copy2darr(input) {
output = create2darr(input.length,input[0].length);
for (i=0;i<input.length;i++) {
for (j=0;j<input[0].length;j++) {
output[j] = input[j];
}
}
return output;
}
function findmax(input) {
Temp = copy1darr(input);
for (i=0;i<Temp.length;i++) {
for (j=0;j<Temp.length-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.length-1;i++) {
document.write(input + " ");
}
document.write(input[input.length-1] + "<b>]</b><br>");
} else {
S = create2darr(input.length,input[0].length);
L = create2darr(S.length,S[0].length);
T = create2darr(S[0].length,S.length);
M = new Array(S[0].length);
for (i=0;i<input.length;i++) {
for (j=0;j<input[0].length;j++) {
S[j] = input[j].toString();
L[j] = S[j].length;
T[j] = L[j];
}
}
for (as=0;as<M.length;as++) {
M[as] = findmax(T[as]);
}
for (i=0;i<S.length;i++) {
for (j=0;j<S[0].length;j++) {
while (S[j].length < 6*(M[j]-S[j].length)) {
S[j] = ' ' + S[j];
}
}
for (i=0;i<S.length;i++) {
switch (i) {
case 0:
document.write("<font face=symbol>é</font>");
break;
case S.length-1:
document.write("<font face=symbol>ë</font>");
break;
default: document.write("<font
face=symbol>ê</font>");
}
for (j=0;j<S.length-1;j++) {
document.write(S[j] + " ");
}
document.write(S[S.length-1]);
switch (i) {
case 0:
document.write("<font face=symbol>ù</font>");
break;
case S.length-1:
document.write("<font face=symbol>û</font>");
break;
default: document.write("<font
face=symbol>ï</font>");
}
document.write("<br>");
}
}
}
a = [
[2.33,43463, 45676786],
[334, 23, 5.3],
[ 3, 2.6, 57087]
];
show(a);