[Newbies] Arrays?

Ben Goetter goetter at mazama.net
Fri Mar 7 00:43:40 UTC 2008


Use Collection>>inject:into:.

#(1 2 3 4 5) inject: 1 into: [ :acc :el | acc * el]
=> 120
#(1 2 3 4 5) inject: 0 into: [ :acc :el | acc + el]
=> 15

-------- Original Message --------
Subject: [Newbies] Arrays?
From: David Zmick <dz0004455 at gmail.com>
To: Squeak Beginners List <beginners at lists.squeakfoundation.org>
Date: Thu Mar 06 2008 16:15:39 GMT-0800 (Pacific Standard Time)
> I have an array of SmallIntegers, and I need to multiply each object 
> in the array by the next.  Each object is a factor, and i need to get 
> to the final number, then store that number in a variable and display 
> it on the transcript.



More information about the Beginners mailing list