I just finished writing my own sort routine for some arrays in my web page because I couldn’t get the .sort() method to work.
Having never used the method before this, I used an example from Danny Goodman’s [U]JavaScript Bible
[code]
function compare(a, b) {
return (a.cmd < b.cmd) ? -1 : 1;
}
for (indx = 0; indx < nodeTbl.length; indx++) {
tblObj = eval(nodeTbl[indx] + “Cmds”);
tblObj.sort(compare);
}
The result was arrays with elements in the reverse order. I’ve probably missed something, but I don’t see it. I added a [b]debugger;[b]a[b]b
Perhaps it was due to the fact that the arrays were being reversed rather than sorted, but my sort routine actually seems to be a bit faster so I’m not unhappy with the results. However, the .sort() method may be useful sometime in the future, if I can figure out how to make it work. ?
Should it have some bearing on the problem, my arrays are created with the following server side generated code:
[code]
var nodeTbl = new Array(‘DEVEL’,’IBAT’,’IOMH’,’ISAT’,’OSAT’,’PRDA’,’PRDB’,’WESTP’);
var DEVELCmds = new Array();
var IBATCmds = new Array();
var IOMHCmds = new Array();
var ISATCmds = new Array();
var OSATCmds = new Array();
var PRDACmds = new Array();
var PRDBCmds = new Array();
var WESTPCmds = new Array();
DEVELCmds[0] = new cmdData(‘PATHCOM $PCOM;STATUS SERVER’,’S PW ‘,’Y’,’SUPERSUPP’);
IBATCmds[0] = new cmdData(‘PATHCOM $PCOM;STATUS SERVER’,’S PW ‘,’Y’,’SUPERSUPP’);
IOMHCmds[0] = new cmdData(‘PATHCOM $PCOM;STATUS SERVER’,’S PW ‘,’Y’,’SUPERSUPP’);
ISATCmds[0] = new cmdData(‘PATHCOM $PCOM;STATUS SERVER’,’S PW ‘,’Y’,’SUPERSUPP’);
OSATCmds[0] = new cmdData(‘PATHCOM $PCOM;STATUS SERVER’,’S PW ‘,’Y’,’SUPERSUPP’);
PRDACmds[0] = new cmdData(‘PATHCOM $PCOM;STATUS SERVER’,’S PW ‘,’Y’,’SUPERSUPP’);
PRDBCmds[0] = new cmdData(‘PATHCOM $PCOM;STATUS SERVER’,’S PW ‘,’Y’,’SUPERSUPP’);
WESTPCmds[0] = new cmdData(‘PATHCOM $PCOM;STATUS SERVER’,’S PW ‘,’Y’,’SUPERSUPP’);
DEVELCmds[1] = new cmdData(‘STATUS’,’TR ‘,’Y’,’SUPERSUPP’);
IBATCmds[1] = new cmdData(‘STATUS’,’TR ‘,’Y’,’SUPERSUPP’);
IOMHCmds[1] = new cmdData(‘STATUS’,’TR ‘,’Y’,’SUPERSUPP’);
ISATCmds[1] = new cmdData(‘STATUS’,’TR ‘,’Y’,’SUPERSUPP’);
OSATCmds[1] = new cmdData(‘STATUS’,’TR ‘,’Y’,’SUPERSUPP’);
PRDACmds[1] = new cmdData(‘STATUS’,’TR ‘,’Y’,’SUPERSUPP’);
PRDBCmds[1] = new cmdData(‘STATUS’,’TR ‘,’Y’,’SUPERSUPP’);
WESTPCmds[1] = new cmdData(‘STATUS’,’TR ‘,’Y’,’SUPERSUPP’);
IBATCmds[2] = new cmdData(‘GOUMP’,’TO ‘,’N’,’SUPERSUPP’);
IBATCmds[3] = new cmdData(‘PATHCOM $IBPD;ABORT TERM’,’S PW ‘,’Y’,’SUPERSUPP’);
IBATCmds[4] = new cmdData(‘PATHCOM $IBPD;START TERM’,’S PW ‘,’Y’,’SUPERSUPP’);
IBATCmds[5] = new cmdData(‘PATHCOM $IBTR;ABORT TERM’,’S PW ‘,’Y’,’SUPERSUPP’);
IBATCmds[6] = new cmdData(‘PATHCOM $IBTR;START TERM’,’S PW ‘,’Y’,’SUPERSUPP’);
IBATCmds[7] = new cmdData(‘PATHCOM $IVPD;ABORT TERM’,’S PW ‘,’Y’,’SUPERSUPP’);
IBATCmds[8] = new cmdData(‘PATHCOM $IVPD;START TERM’,’S PW ‘,’Y’,’SUPERSUPP’);
IBATCmds[9] = new cmdData(‘RESETCAM’,’TR ‘,’N’,’SUPERSUPP’);
IBATCmds[10] = new cmdData(‘RSTRTCAM’,’TR ‘,’N’,’SUPERSUPP’);
// etc., etc. ….
and this function from my .js file.
[code]
function cmdData(cmd, cmdcode, preq, svr) {
// custom object constructor
this.cmd = cmd;
this.cmdcode = cmdcode;
this.preq = preq;
this.svr = svr;
return;
}