really silly question

Jon Hylands jon at huv.com
Fri Aug 31 02:49:49 UTC 2001


On Fri, 31 Aug 2001 03:36:19 +0100, John Hinsley <jhinsley at telinco.co.uk>
wrote:

> Given two arrays of the same size filled with numbers, can someone give
> me a code snippet that will show me how to add the numbers at the same
> index to produce a third array?
> 
> So that firstArray:= #(1 2 3 4)
> 	secondArray:= #(5 6 1 2)
> 
> will result in a thirdArray (6 8 4 6)

Try:

thirdArray := (1 to: firstArray size) collect: [:index |
	(firstArray at: index) + (secondArray at: index)]

Later,
Jon

--------------------------------------------------------------
   Jon Hylands      Jon at huv.com      http://www.huv.com/jon

  Project: Micro Seeker (Micro Autonomous Underwater Vehicle)
           http://www.huv.com




More information about the Squeak-dev mailing list