[Newbies] Sorting

Mark Bailey Mark.Bailey at sas.com
Thu May 17 12:24:03 UTC 2007


<< #sortBy: does not return a string. >>

I was surprised that the collection returned does not respond to a message like asString. Anyway, this short code works:

t _ ('The cow jumped over the moon' sortBy: [ :x :y | x < y ]).
s _ String new: t size.
1 to: t size do: [ :i | s at: i put: (t at: i) ].

You can also apply this approach based on inject:into:

t _ ('The cow jumped over the moon' sortBy: [ :x :y | x < y ]).
t inject: String new into: [ :x :y | x, (String with: y) ].

Mark


More information about the Beginners mailing list