[Newbies] Sorting

Scott Wallace madevu at pacbell.net
Thu May 17 17:16:07 UTC 2007


Try ('The cow jumped over the mon' sortBy: [:x :y | x < y]) as: String.


On May 17, 2007, at 5:24 AM, Mark Bailey wrote:

> << #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
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners



More information about the Beginners mailing list