2 Replies Latest reply on Oct 27, 2006 7:17 PM by jonnybennett

# array manipulation

Okay a little teaser for you:

I have an array of strings. I need to re-order the order of the array so that they are in ascending in order dependant on the number in the third split('|') of the string.
I then need to change that value so that it will take on the value 0 for the smalest and incrementing up for the next and so on.

d[0]='a|1|95|2|60|200|200';
d[1]='b|1|15|2|60|200|200';
d[2]='c|1|8|2|60|200|20';
d[3]='d|1|4|2|60|200';
d[4]='e|1|9|2|60|200';

for (p=0;p<d.length;p++){
arrayDetails=d[p].split('|');
sortDetailsArray[p]=Number(arrayDetails[2]);}

therefore I need my new array to output:

dnew[0]='d|1|0|2|60|200';
dnew[1]='c|1|1|2|60|200|20';
dnew[2]='e|1|2|2|60|200';
dnew[3]='b|1|3|2|60|200|200';
dnew[4]='a|1|4|2|60|200|200';

I have struggled with this for ages, and my brain hurts, please have a go, thnks Jonnie.
• ###### 1. Re: array manipulation
Try this:

Tim

• ###### 2. Re: array manipulation
brilliant. Thanks very much. I wish I understood it!, but it works perfectly. I will study it and try and understand it, and maybe one day I will be as clever as you. Thanks very much.