No matter how experienced you are with a language, it's a good idea to frequently browse the documents. You can find useful methods that you hadn't used before...or at least not on a daily basis or even remotely recently.
So, as I started to tackle the problem I imagined looping through the array with a function that would reposition each element based on the values of their four properties. If two elements had equivalent values for a property, compare the next property. Something like the following pseudo code
for length of array
{
if ( i.p1 < i-1.p1){
move i in front of i-1
else if(i.p1 == i-1.p1){
if(i.p2 < i-1.p2){
move i in front of i-1
} else if(i.p2 == i-1.p2){
. . .
}
}
}
myArray.sortOn(["p1", "p2", "p3", "p4"], Array.NUMERIC | Array.DESCENDING);
which does the job quite nicely.
0 comments:
Post a Comment