Re: sort these records?
Re: sort these records?
- Subject: Re: sort these records?
- From: deivy petrescu <email@hidden>
- Date: Wed, 28 May 2008 18:30:10 -0400
On May 28, 2008, at 17:35, Mark J. Reed wrote:
On Wed, May 28, 2008 at 5:16 PM, <email@hidden> wrote:
Hudson, here is a beginning it is not optimized,that is, it is good
for
short lists, and it will give you an empty record at the end or at
the
beginning, it is easy to remediate that, so ... it is up to you.
Whence the empty record? It looks like a basic Quicksort...
Mark,
It comes because I used to wrong concatenation.
Changing the code a bit we do not get the empty record.
Here is the new code:
<script>
set rec to {{owner:"Dom", cats:{"Sane", "Crazy"}}, {owner:"Andy", cats:
{"Hip", "Dip"}}}
sort(rec)
on sort(l)
if (count of l) < 2 then return l
set m to item 1 of l
set rl to rest of l
set l2 to {}
set l1 to {}
repeat with j in rl
set j to contents of j
if owner of j > owner of m then
set end of l2 to j -- this is different
else
set end of l1 to j -- so is this
end if
end repeat
return sort(l1) & {m} & sort(l2)
end sort
<script>
I owe you 2 today... :)
Deivy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden