Arrays?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Arrays?

David Zmick
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.

display
    array do: [:in| self num: num * in. ].
    Transcript cr; show: 'The factors are: '; show: stream contents; cr.
    Transcript show: 'The final number is: '; show: num; cr.

the stream is on the array
--
David Zmick
/dz0004455\
http://dz0004455.googlepages.com
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Arrays?

Ben Goetter
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 <[hidden email]>
To: Squeak Beginners List <[hidden email]>
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.

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Arrays?

Michael van der Gulik-2
In reply to this post by David Zmick


On Fri, Mar 7, 2008 at 1:15 PM, David Zmick <[hidden email]> wrote:
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.

display
    array do: [:in| self num: num * in. ].
    Transcript cr; show: 'The factors are: '; show: stream contents; cr.
    Transcript show: 'The final number is: '; show: num; cr.

the stream is on the array


What is your question?

Gulik.

--
http://people.squeakfoundation.org/person/mikevdg
http://gulik.pbwiki.com/
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Arrays?

David Zmick
o nevermind, i figured it out.

display
    stream contents do: [:in| self num: num * in. ].
    Transcript cr; show: 'The factors are: '; show: stream contents; cr.
    Transcript show: 'The final number is: '; show: num; cr.

On Thu, Mar 6, 2008 at 6:47 PM, Michael van der Gulik <[hidden email]> wrote:


On Fri, Mar 7, 2008 at 1:15 PM, David Zmick <[hidden email]> wrote:
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.

display
    array do: [:in| self num: num * in. ].
    Transcript cr; show: 'The factors are: '; show: stream contents; cr.
    Transcript show: 'The final number is: '; show: num; cr.

the stream is on the array


What is your question?

Gulik.

--
http://people.squeakfoundation.org/person/mikevdg
http://gulik.pbwiki.com/

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners




--
David Zmick
/dz0004455\
http://dz0004455.googlepages.com
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners