[Newbies] Array questions
peace_the_dreamer at yahoo.com
Fri Apr 23 22:48:46 UTC 2010
--- On Fri, 4/23/10, noobie <pntball650 at aol.com> wrote:
> From: noobie <pntball650 at aol.com>
> Subject: [Newbies] Array questions
> To: beginners at lists.squeakfoundation.org
> Date: Friday, April 23, 2010, 6:07 PM
> I have a few questions about writing methods dealing with
> Firstly, how would i make a method that returns true or
> false if the
> receiver is in the array.
> 1 inArray: #(1 2 3 4)
> should return to true
^theArray includes: self .
> Second, how would i make a method that will return the
> number of integers in
> the array different from the integer parameter
> anArray howmany: 5 should return how many
> elements in the array are
> different from the number
^(self reject: [ :each |
each = anItem ]) size .
change reject to select to get the number that are the item.
You are asking very elementry questions here. You may be ready to read some of the literature.
I highly recommend Kent Becks book on Smalltalk.
Smalltalk Best Practice Patterns by Kent Beck
> thanks again.
More information about the Beginners