Actually that is the hidden gem on all of this - thinking about the common
things people do through new eyes, has forced me to learn new things (and that
feels very compatible with Pharo).
I also thank everyone here for entertaining these questions and hopefully help
build another way for
The good thing about these exercises is that you know about new selectors,
I didn't know there was an #allButLast and #allButLastDo:.
Regards,
Esteban A. Maringolo
On Fri, May 17, 2019 at 5:44 AM Sven Van Caekenberghe wrote:
> I would make that
>
> ^ String new: gifts size * 10
I would make that
^ String new: gifts size * 10 streamContents: [ :stream |
gifts allButLastDo: [:each |
stream nextPutAll: each; nextPutAll: ', '].
stream nextPutAll: 'and '; nextPutAll: gifts last ]
Your iteration is well done, clear and to the point.
> On 17 May 2019, at 02:44,
stream := WriteStream on: (String new: gifts size * "estimated size per
gift" 10).
"The number after #new: is the *initial* allocation; the stream will
reallocate it
as needed."
gifts allButLastDo: [:each |
stream nextPutAll: each; nextPutAll: ', '].
stream nextPutAll: 'and '; nextPutAll:
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".
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 wrote:
> and this is working
>
> String
> streamContents: [ :stream |
> gifts
and this is working
String
streamContents: [ :stream |
gifts allButLast
do: [ :each | stream nextPutAll: each ]
separatedBy: [ stream
nope, it takes also the last one and
that schould not be used.
Op 16-5-2019 om 21:51 schreef Roelof Wobben:
I think this is better
^ String streamContents: [:stream |
gifts
do: [:each | stream
Sorry, I misses the "all" part at the end (I don't see how that could add
something, but if it's in the requirements...)
Then it should be like this:
String streamContents: [:stream |
gifts allButLast
do: [:each | stream nextPutAll: each ]
separatedBy: [ stream nextPut: $,; space ].
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
oke, and then do something like :
stream :=
String streamContents: [:stream |
gifts
do: [:each | stream nextPutAll: each ]
separatedBy: [ stream nextPut: $,; space ]
]
stream nextputAll: 'all'
stream nextPut: ','
stream nextPut: gifts last
Roelof
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 wrote:
> Hello,
>
> Im testing all my
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 ' ,
13 matches
Mail list logo