logo       

RE: Sorting: msg#00070

lang.smalltalk.squeak.beginners

Subject: RE: Sorting

<< #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


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise