Date: Thu, 2 Mar 1995 18:05:34 -0800 From: David Miller <davem@PANGEA.STANFORD.EDU> Subject: Lingo: sorting property lists by value > Is there a way to sort property lists with their values as the criteria?This handler will sort a property list from largest to smallest value. Some points:
on SortPropListDec myList --doesn't work with sorted list; writes over myList
if count(myList) then
set myMinVal = min(myList)
set myPos = getPos(myList,myMinVal)
set myProp = getPropAt(myList, myPos)
deleteAt(myList, myPos)
SortPropListDec(myList)
addProp myList, myProp, myMinVal
end if
end
Date: Sat, 4 Mar 1995 09:43:41 +0000 From: Peter Small <peter@GENPS.DEMON.CO.UK> Subject: Re: Lingo: sorting property lists by valueHere's a little function that may do the trick for you.
Call it with:
SortApropListByValue(yourPropList)
on SortApropListByValue propL --function
set linList to []
set sortedProp to [:]
repeat with i in propL
append linList,i
end repeat
sort linList
put count(propL) into EntNum
repeat with p in linList
repeat with q = 1 to entNum
if p = getAt(propL,q) then
addProp sortedProp,getpropAt(propL,q),getAt(propL,q)
setAt propL,q,maxInteger()
end if
end repeat
end repeat
return sortedProp --RETURNS YOUR LIST SORTED BY VALUE
end