Re: Sorting
Re: Sorting
- Subject: Re: Sorting
- From: Sascha Kuehn <email@hidden>
- Date: Sun, 5 Oct 2003 20:14:45 +0200
thanks a lot. this script works really good. and its very fast too!
@ Robert
!B == *leq* == "less or equal to" == type alt -<
On Sunday, October 5, 2003, at 05:58 PM, Deivy Petrescu wrote:
On Sunday, Oct 5, 2003, at 10:15 US/Eastern, Sascha Kuehn wrote:
sounds good but i'm looking for a free solution!!
sascha
Sascha, this script is a tweak of satimage's sort code.
The original version is by Emmanuel Levy.
I did not try to write any error checking, this is left as an
exercise, however, this is a working script.
Bacause the mailer will screw up the less or equal sign, I'll
substitute it by *leq*. So when you see *leq*, type alt -<.
Now one may think that this is a flaw in the server, which it is not.
In its infinite wisdom, the mailer has decided that the sign "less or
equal to" is offensive to cultures, so it decided to do away with it,
and other offensive symbols that people on this list may inadvertently
write.
Because we are not that bright, we tend to complain. But you know who
knows better....
Note lista is your list.
coluna is the colunm you want the list sorted by.
tipo is the type, either up or down. I did not put any error checking,
mind you.
set lista to {{"a", "cc", "bbb", "dddd"}, {"b", "aa", "ddd", "cccc"},
{"c", "dd", "aaa", "bbbb"}, {"d", "bb", "ccc", "aaaa"}}
sort(lista, 3, up)
on sort(lista, coluna, tipo)
set len to length of lista
if len = 1 then return lista
set y to (item coluna of (item 1 of lista))
set x to (item 1 of lista)
set lista to (rest of lista)
set lista1 to {}
set lista2 to {}
set len to length of lista
if tipo is down then
repeat with k from 1 to len
set i to contents of (item coluna of (item k of lista))
if y > i then
set end of lista2 to ((item k of lista) as list)
else
set end of lista1 to ((item k of lista) as list)
end if
end repeat
if (length of lista1 *leq* 1) and (length of lista2 *leq* 1) then
return lista1 & {x} & lista2
else
return sort(lista1, coluna, tipo) & {x} & sort(lista2, coluna, tipo)
end if
else if tipo is up then
repeat with k from 1 to len
set i to contents of (item coluna of (item k of lista))
if y < i then
set end of lista2 to ((item k of lista) as list)
else
set end of lista1 to ((item k of lista) as list)
end if
end repeat
if (length of lista1 *leq*1) and (length of lista2 *leq* 1) then
return lista1 & {x} & lista2
else
return sort(lista1, coluna, tipo) & {x} & sort(lista2, coluna, tipo)
end if
end if
end sort
--->{{"c", "dd", "aaa", "bbbb"}, {"a", "cc", "bbb", "dddd"}, {"d",
"bb", "ccc", "aaaa"}, {"b", "aa", "ddd", "cccc"}}
Regards
Deivy Petrescu
http://www.dicas.com/
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
References: | |
| >Re: Sorting (From: Deivy Petrescu <email@hidden>) |