I implemented it for fun and noticed that in your test data, the first 16 is gone. So, groupings are wrong with all methods proposed in a sense.

With Richard's version, we get this in Pharo

#(16 17 17 16 18 17 18 19 19 19 18 19 19 20 19 20 19 20 20 20 19 20) ��splitEvery: 7

"an OrderedCollection(#(16 17 17 16 18 17 18) #(19 19 19 18 19 19 20) #(19 20 19 20 20 20 19) #(20))"

splitEvery: chunkSize
��"Answer a collection of sub-collections each of the specified chunk size.
�� If the receiver size is not a multiple of chunkSize, the last sub-collection will be shorter."

��
��| chunks stream |
��chunkSize < 1 ifTrue: [ ^self splitEvery: 1 ].
��
��stream := ReadStream on: self.
��chunks := OrderedCollection new.
��[stream atEnd] whileFalse: [
�� chunks add: (stream next: chunkSize).
��].
��
��^chunks.

Phil


On Wed, Apr 26, 2017 at 8:38 AM, Stephane Ducasse <stepharo.self@gmail.com> wrote:
we do not have nextOrLess: in Pharo.��

On Wed, Apr 26, 2017 at 6:19 AM, Richard Sargent <rsargent@5x5.on.ca> wrote:
In 2003, I implemented the following method. It is something that comes up from time to time.
��
!SequenceableCollection publicMethods !
splitEvery: chunkSize
��"Answer a collection of sub-collections each of the specified chunk size.
�� If the receiver size is not a multiple of chunkSize, the last sub-collection will be shorter."
��
��| chunks stream |
��chunkSize < 1 ifTrue: [ ^self splitEvery: 1 ].
��
��stream := ReadStream on: self.
��chunks := OrderedCollection new.
��[stream atEnd] whileFalse: [
����chunks add: (stream nextOrLess: chunkSize).
��].
��
��^chunks.
! !


From: Pharo-users [mailto:pharo-users-bounces@lists.pharo.org] On Behalf Of Stephane Ducasse
Sent: April 25, 2017 13:08
To: Any question about pharo is welcome
Subject: [Pharo-users] little "challenge"

#(16 �� ��17 17 16 18 17 18 19 �� ��19 19 18 19 19 20 19 �� 20 19 20 20 20 19 20)��

->��

{ #(17 17 16 18 17 18 19) . #(19 19 18 19 19 20 19) . #(20 19 20 20 20 19 20)}

any code?