"Kinky" sort...

Mark Smith masmit at gmail.com
Mon Sep 19 11:30:48 EDT 2005


Ah, I think I see what you mean. How about this:

  repeat for each line L in vData
     if item 3 of L is not empty then put item 3 of L into currentGroup
     put L & cr after groupArray[currentGroup]
   end repeat

   put the keys of groupArray into kList
   sort lines of kList
   repeat for each line L in kList
     sort lines of groupArray[L] by item 4 of each
     put groupArray[L] & cr after sortedList
   end repeat

   filter sortedList without empty

which gives:

1,text 1,group1,20050104
8,text 8,group1,20050104
9,text 9,,20050204
2,text 2,group1   20050104
5,text 5,group2   20050104
7,text 7,,20050104
6,text 6,,20050204
3,text 3,group2   20051004
10,text 10,group3,20050104
4,text 4,group3   20051004


On 19 Sep 2005, at 16:15, Ton Kuypers wrote:

>> repeat for each line L in vData
>>   -- split the data into an array using the group as keys (no  
>> group lines go into groupZ)
>>     if item 3 of L is not empty then
>>       put L & cr after groupArray[item 3 of L]
>>     else
>>       put L & cr after groupArray[groupZ]
>>     end if
>>   end repeat
>>   put the keys of groupArray into kList
>>   sort lines of kList
>>   repeat for each line L in kList
>>     sort lines of groupArray[L] numeric by item 4 of each
>>     put groupArray[L] & cr after theSortedList
>>   end repeat
>>
>>   filter theSortedList without empty -- strip any empty lines from  
>> trailing crs
>




More information about the use-livecode mailing list