any ihint how to do this
On Mon, Dec 10, 2018 at 8:52 AM Roelof Wobben <r.wobben@home.nl> wrote:
Hello,
is there a way I can check if a word has 2 the same chars after each other I was hoping that '#groupby could help me but that one sorts so abba the aa is found or do I have to use a stream for that
could I then also use that stream to check if a word contains 3 vowels ?
I'll start with this question first, since it is the easiest to discuss. The brute-force approach would be to use #select: against the word to extract all the vowels. But a better approach, would be to imagine what you need and delegate it. So, we already have #select:, #reject, #detect:, and #collect: as patterns. Imagine a new method called #count:, and implement that. (For the purpose of the assignment, implementing #count: is probably overkill, unless you have many, many words to check.) Now, back to the first question. You want to iterate through the word "pairwise", where you examine each successive pair of letters. So, you want to iterate from 1 through n-1 and check whether the letter at the index is the same as the letter at the index + 1. That should be enough to get you going.
I ask also on the discord app but no answer for a long time
Regards,
Roelof
Having imagined collection count: [:each | ...] DO NOT IMPLEMENT IT! Check to see if it already exists. Hint: it DOES exists and has done since before Pharo. So 'pangrams are fun but this isn''t one' count: [:each | each isVowel] already answers 10. Something that may help you a lot is to visit the Collection class in the browser, and read every method in the 'enumerating' category. (You will benefit from looking at the others too, but we are staying focussed.) When you have done that, visit the SequenceableCollection class, and read every method in its 'enumerating' category. For example, you will certainly find #overlappingPairsDo:. Given that, you can add overlappingPairsAnySatisfy: testBlock self overlappingPairsDo: [:x :y | (testBlock value: x value: y) ifTrue: [^true]]. ^false And now you can test for two adjacent equal elements using aSequence oberlappingPairsAnySatisfy: [:x :y | x = y] On Tue, 11 Dec 2018 at 06:05, Richard Sargent < richard.sargent@gemtalksystems.com> wrote:
On Mon, Dec 10, 2018 at 8:52 AM Roelof Wobben <r.wobben@home.nl> wrote:
Hello,
is there a way I can check if a word has 2 the same chars after each other I was hoping that '#groupby could help me but that one sorts so abba the aa is found or do I have to use a stream for that
could I then also use that stream to check if a word contains 3 vowels ?
I'll start with this question first, since it is the easiest to discuss. The brute-force approach would be to use #select: against the word to extract all the vowels. But a better approach, would be to imagine what you need and delegate it. So, we already have #select:, #reject, #detect:, and #collect: as patterns. Imagine a new method called #count:, and implement that. (For the purpose of the assignment, implementing #count: is probably overkill, unless you have many, many words to check.)
Now, back to the first question. You want to iterate through the word "pairwise", where you examine each successive pair of letters. So, you want to iterate from 1 through n-1 and check whether the letter at the index is the same as the letter at the index + 1. That should be enough to get you going.
I ask also on the discord app but no answer for a long time
Regards,
Roelof
participants (4)
-
Richard O'Keefe -
Richard Sargent -
Roelof Wobben -
Torsten Bergmann