Home   Archive   Permalink



Sorting objects

I hope this will be helpful for beginners:
you have 2 or more objects and you want to sort them with sort function.
    
Here how you do this,
     o: context [name: "def"]
     p: context [name: "abc"]
     k: context [name: "bae"]
and you compare function,
     f: func [x y] [x/name < y/name]
you can try this,
     f o p
     >> false
     f p k
     >> true
and the last step,
     d: sort/compare reduce [o p k] :f
d will be (will point to) [p k o] which is the sorted objects.

posted by:   Endo     18-Jun-2010/17:33-7:00