As a newbie I have lots to learn.

Thank you so much,
Eric


--- James Newton <[EMAIL PROTECTED]> wrote:
> eric terry <[EMAIL PROTECTED]> wrote:
> > [#userID: "Bob" , #minimumBet: "50", #userLevel:
> "20"]
> > [#userID: "Phil" , #minimumBet: "10", #userLevel:
> "80"]
> > [#userID: "Ron" , #minimumBet: "25", #userLevel:
> "10"]
> > [#userID: "Jay" , #minimumBet: "75", #userLevel:
> "40"]
> > 
> > Is there a way to sort that via #minimumBet or
> > #userLevel?
> 
> Hi Eric,
> 
> Here's a handler that returns a duplicate proplist
> sorted by value:
> 
> on mSortByValue(aPropList)
> -------------------------------------------
>   -- RETURNS a property list with the same props and
> values as
>   -- aPropList, but sorted by value.  A separate
> list is returned,
>   -- since the original aPropList may already be
> sorted by prop, and
>   -- there is no way to unsort it
>  
>
--------------------------------------------------------------------
>   
>   if ilk(aPropList) <> #propList then
>     -- No sorting is possible
>     return aPropList
>   end if
> 
>   tCount = aPropList.count
>   
>   -- Create a sorted list where values = props and
> vice versa
>   tValueList = [:]
>   tValueList.sort()
>   repeat with i = 1 to tCount
>     tValueList.setaProp(aPropList[i],
> aPropList.getPropAt(i))
>   end repeat
>   
>   -- Inverse the props and values a second time
>   tPropList = [:]
>   repeat with i = 1 to tCount
>     tPropList.setaProp(tValueList[i],
> tValueList.getPropAt(i))
>   end repeat
>   
>   return tPropList
> end mSortByValue
> 
> 
> -- IN THE MESSAGE WINDOW
> 
> x = [#a: 3, #b: 2, #c: 1, #d: 9, #e: 8, #f: 6, #g:
> 5, #h: 4, #i: 0, #j: 7]
> x.sort()
> put mSortByValue(x)
> -- [#i: 0, #C: 1, #B: 2, #A: 3, #h: 4, #g: 5, #f: 6,
> #j: 7, #e: 8, #d: 9]
> 
> 
> 
> And here's a handler that answers your question:
> 
> on sortByValueInSubList(aListOfLists, aProp)
>   tCount = aListOfLists.count
>   tList = [:]
>   tList.sort()
>   
>   repeat with i = 1 to tCount
>     tSubList = aListOfLists[i]
>     tValue   = tSubList[aProp]
>     tList.setAProp(tValue, tSubList)
>   end repeat
>   
>   aListOfLists.deleteAll()
>   repeat with i = 1 to tCount
>     aListOfLists.append(tList[i])
>   end repeat
> end repeat
> 
> 
> -- IN THE MESSAGE WINDOW
> 
> x = [[#userID: "Bob" , #minimumBet: "50",
> #userLevel: "20"], [#userID:
> "Phil" , #minimumBet: "10", #userLevel: "80"],
> [#userID: "Ron" ,
> #minimumBet: "25", #userLevel: "10"], [#userID:
> "Jay" , #minimumBet: "75",
> #userLevel: "40"]]
>   
> sortByValueInSubList(x, #userLevel)
> put x
> -- [[#userID: "Ron", #minimumBet: "25", #userLevel:
> "10"], [#userID: "Bob",
> #minimumBet: "50", #userLevel: "20"], [#userID:
> "Jay", #minimumBet: "75",
> #userLevel: "40"], [#userID: "Phil", #minimumBet:
> "10", #userLevel: "80"]]
> 
> 
> Cheers,
> 
> James
> 
> 
> [To remove yourself from this list, or to change to
> digest mode, go to
> http://www.penworks.com/lingo-l.cgi  To post
> messages to the list,
> email [EMAIL PROTECTED]  (Problems, email
> [EMAIL PROTECTED])
> Lingo-L is for learning and helping with programming
> Lingo.  Thanks!]
> 


__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com

[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to