I would say that you should follow a pattern like this:
(collectionToTest
indexOfSubCollection: (
Array
new: numberOfRepetitions
withAll: desiredObject)
startingAt: 1
) isZero not
Maybe I don’t know some useful methods in Pharo, but if you define such as:
SequenceableCollection >> indexOfSubCollection: aSubCollection
^ aSubCollection indexOfSubCollection: aSubCollection startingAt: 0
SequenceableCollection >> containsSubCollection: aSubCollection
^ (aSubCollection indexOfSubCollection: aSubCollection) isZero not
Object >> asArrayOf: aLength
^ Array new: aLength withAll: self
then the definition can be smoothed to:
collectionToTest containsSubCollection:
(desiredObject asArrayOf: numberOfRepetitions)
or for your example:
anArray containsSubCollection: (5 asArrayOf: 10)
PS I'm not sure about method names. Maybe, inArrayOf:maybe better asArrayOf:, etc.
source
share