[Newbies] How to doubble sort a collection

Raymond Asselin jgr.asselin at me.com
Wed Feb 4 23:40:27 UTC 2015


I finaly found the problem witch was not in the code suggest but behind the keyboard.

In fact when the time is generated everything is good , when i entered it by hand = this is a String.
So I had in the sorting code:  
> ^notes sort:[:a :b | (a date = b date) and:[a temps asTime > b temps asTime ]] .




> Le 2015-02-04 à 14:40, Chris Cunningham <cunningham.cb at gmail.com> a écrit :
> 
> 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 <mailto: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 <mailto: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 <mailto:Beginners at lists.squeakfoundation.org>
> http://lists.squeakfoundation.org/mailman/listinfo/beginners <http://lists.squeakfoundation.org/mailman/listinfo/beginners>
> 
> _______________________________________________
> 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/4b02ba88/attachment.htm


More information about the Beginners mailing list