I made the error somehow.
Sorry for the confusion.

Roelof


Op 16-5-2019 om 22:29 schreef Esteban Maringolo:
Oh... the expected output was 'e1, e2, e3 and e4', I read "all" instead of "and".

Now it makes sense.

Esteban A. Maringolo


On Thu, May 16, 2019 at 5:09 PM Roelof Wobben <r.wob...@home.nl> wrote:
and this is working

String
                streamContents: [ :stream |
                    gifts allButLast
                        do: [ :each | stream nextPutAll: each ]
                        separatedBy: [ stream
                                nextPut: $,;
                                space ].
                    stream
                        nextPut: $,;
                        nextPutAll: ' and ';
                        nextPutAll: gifts last ] ]

Thanks Estaban for the hint.

Roelof



Op 16-5-2019 om 21:51 schreef Roelof Wobben:
I think this is better

 ^  String streamContents: [:stream |
 gifts 
    do: [:each | stream nextPutAll: each ]
    separatedBy: [ stream nextPut: $,; space ]
  stream nextputAll: 'all'; nextPut: ','; nextPut: gifts last] 


Op 16-5-2019 om 21:47 schreef Roelof Wobben:
oke, and then do something like :

stream :=
String streamContents: [:stream |
  gifts 
    do: [:each | stream nextPutAll: each ]
    separatedBy: [ stream nextPut: $,; space ]
     
stream nextputAll: 'all'; nextPut: ','; nextPut: gifts last
]

stream nextputAll: 'all' 
stream nextPut: ','
stream nextPut: gifts last


Roelof


Op 16-5-2019 om 21:30 schreef Esteban Maringolo:
Maybe this is a better way to build what you want.
String streamContents: [:stream |
  gifts 
    do: [:each | stream nextPutAll: each ]
    separatedBy: [ stream nextPut: $,; space ]
]

Esteban A. Maringolo


On Thu, May 16, 2019 at 4:21 PM Roelof Wobben <r.wob...@home.nl> wrote:
Hello,

Im testing all my solutions with critiz and can solve almost all problems,

Only this one I cannot figure out.

I have this code
(gifts allButLast
                inject: ''
                into: [ :str :each | str , each , ', ' ]) , 'and ' , gifts last ]

and critiz says I should use a stream .

How can I make this work ? 

Roelof





Reply via email to