In this environment, I only have access to intrinsic Javascript functions, so cannot load external libraries.
When trying to sort by 3 keys, inner, middle, and outer, only my last sort seems to be preserved.
function Claim(claimNumber, lastName, claimStatus, record)
{
this.claimNumber = claimNumber;
this.lastName = lastName;
this.claimStatus = claimStatus;
this.record = record;
}
function sortLastName(a, b) {
var o1 = a["lastName"].toUpperCase();
var o2 = b["lastName"].toUpperCase();
if (o1 < o2) return -1;
if (o1 > o2) return 1;
return 0;
}
function sortClaimNumber(a, b) {
var o1 = a["claimNumber"].toUpperCase();
var o2 = b["claimNumber"].toUpperCase();
if (o1 < o2) return -1;
if (o1 > o2) return 1;
return 0;
}
function sortClaimStatus(a, b) {
var o1 = ("00" + a["claimStatus"].toUpperCase()).substr(-2);
var o2 = ("00" + b["claimStatus"].toUpperCase()).substr(-2);
if (o1 < o2) return 1;
if (o1 > o2) return -1;
return 0;
}
var claimListArray = buildClaimList(record);
claimListArray.sort(sortClaimStatus);
claimListArray.sort(sortClaimNumber);
claimListArray.sort(sortLastName);
The output should look like (lastname asc, claimnumber asc, claimstatus desc):
AARDVARK 111222A 15
AARDVARK 111222A 6
AARDVARK 111222A 1
AARDVARK 222555C 8
AARDVARK 222555C 4
BANKS 123132Z 78
but instead looks like:
AARDVARK 111222A 15
AARDVARK 222555C 4
AARDVARK 111222A 1
AARDVARK 222555C 8
AARDVARK 111222A 6
BANKS 123132Z 78
That is to say, only the lastName sort is preserved, as if the first two sorts did not happen. Is there something about arrays and sorting that I'm missing that ignores previous sorts?
Is there a better approach?