--- On Fri, 4/23/10, noobie pntball650@aol.com wrote:
From: noobie pntball650@aol.com Subject: [Newbies] Array questions To: beginners@lists.squeakfoundation.org Date: Friday, April 23, 2010, 6:07 PM
I have a few questions about writing methods dealing with arrays....
Firstly, how would i make a method that returns true or false if the receiver is in the array. example 1 inArray: #(1 2 3 4) should return to true
inArray: theArray
^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
howMany: anItem
^(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 e.g.: http://www.amazon.com/Smalltalk-Best-Practice-Patterns-Kent/dp/013476904X/re...
thanks again.