Use: Case 1: Basic sort var X = Sort(data); data is either a String or Array. Returns a String or Array that is sorted ascending, case sensitive Case 2: Sort by column/property var X = Sort(data, path); data is an Array of Arrays or Objects, all of which are homogenous. path is a Number, String or Array, or null. If it's a number, it's the index into the child Arrays. If it's a String, it's the property name of the child objects. If it's an Array, it's the path into the child objects (ie: ['this','that'] would point into child.this.that. If it's null/undefined, data is treated as in case 1 (default). Case 3: Sort ascending/descending var X = Sort(data, path, ascending); data and path are as in cases 1 and 2 ascending is Boolean, Number, String or null. If a Boolean, 'true' means sort ascending. If a Number, 0 means descending, all others mean ascending. If a String, 'asc' or 'ascending' means ascending, all others mean descending. If null, sorts ascending (default). Case 4: Sort by custom function var X = Sort(data,path,ascending,sortFunction); data,path and ascending are as in previous cases. sortFunction is a function that takes two arguments and returns a boolean, where a 'true' return value means that the arguments, in the order passed, are already sorted. Case 5: (browser or CScript only!) Sort.testSuite() Use for regression testing when adding new features. Tests the basic needs for the script. function Sort(data,att,asc,fnc) { try { switch (typeof data) { case 'undefined': throw new Error(false,'First argument (data) is NEVER optional.'); case 'string': var tod=1; if (typeof att!='undefined'&&att!=null) throw new Error(false,'To sort a string, second argument (attribute) MUST be null or undefined. I was passed a '+(typeof att)+'!'); var tmp=Array(); for (i=0; i1) { var mid=min+Math.ceil(len/2)-1; var b1=Sort.process(data,att,asc,fnc,min,mid); var b2=Sort.process(data,att,asc,fnc,mid+1,max); var b1c, b2c; var ret=Array(); var v1,v2; for (b1c=b2c=0; b1c=b2.length) ret.push(b1[b1c++]); else if (b1c>=b1.length) ret.push(b2[b2c++]); else if (!asc^fnc(Sort.descend(b1[b1c],att),Sort.descend(b2[b2c],att))) ret.push(b1[b1c++]); else ret.push(b2[b2c++]); } if (typeof tod!='undefined') return ret.join(''); return ret; }else{ return [data[min]]; } } //NOT FOR YOU! Sort.descend = function (item,path) { if (typeof path!='object'||typeof path.length!='number') throw new Error(false,'Sort.descend only takes an Array as its second parameter. Also, YOU shouldn\'t be using it.'); for (var i=0; i'; return true; } return false; } //'Constants' for the user //Use in arg 2 (path to sorted value) Sort.noPath = null; //Use in arg 3 (ascending/descending switch) Sort.ascending=true; Sort.descending=false; //Use in arg 4 (sort function) Sort.scalar = function (a,b) { return a