Inject problem

Hi
In inject method , everytime that inject called what is returned ? for
example in this code everytime what is returned ?

array = [*1…10]
array.inject(0) { | memo , item | memo + item }

On Tue, Aug 3, 2010 at 1:55 PM, Amir E. [email protected]
wrote:

In inject method , everytime that inject called what is returned ? for
example in this code everytime what is returned ?

array = [*1…10]
array.inject(0) { | memo , item | memo + item }

irb(main):001:0> array = [*1…10]
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
irb(main):002:0> array.inject(0) { | memo , item | puts
“#{memo}\t#{item}”; memo + item }
0 1
1 2
3 3
6 4
10 5
15 6
21 7
28 8
36 9
45 10
=> 55

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs