[Newbies] How to doubble sort a collection

Chris Cunningham cunningham.cb at gmail.com
Wed Feb 4 19:40:10 UTC 2015


You have a logic issue with the first one:
sortedNotes
^notes sort:[:a :b | (a date = b date) and:[a temps > b temps]] .
This is saying that the the two dates are different, then false.  For this
you probably want to be something like:
sortedNotes
^notes sort:[:a :b | a date > b date or: [(a date = b date) and:[a temps >
b temps]]] .

-cbc

On Wed, Feb 4, 2015 at 10:22 AM, Raymond Asselin <jgr.asselin at me.com> wrote:

> For now I implemented:
>
> sortedNotes
> ^notes sort:[:a :b | (a date = b date) and:[a temps > b temps]] .
>
> AND
>
> notesSorted
> ^notes sort:[:a :b | a date = b date
>                 ifTrue:[a temps > b temps]
>                 ifFalse:[a date > b date]] .
>
> does exactly the same result.
>
> But there is still notes in a same date that do not sort correctly, the
> begining is good and after 5 or so objects
> I get some witch do not seem to be sorted.
>
> BTW don't know the difference between sort:  and sorted:
> it seems as if the last one produce a new collection and the first one
> produce same collection but sorted.
>
> Note: I use 24 hours instead of a.m. / p.m. is this may cause problems?
>
> > Le 2015-02-04 à 12:00, Paul DeBruicker <pdebruic at gmail.com> a écrit :
> >
> > a date = b date
> >   ifTrue:[a temps > b temps]
> >   ifFalse:[a date > b date]
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20150204/5b56c51b/attachment.htm


More information about the Beginners mailing list