From: Dan Diebolt Date: 2008-03-26T23:43:13+09:00 Subject: Re: The inject function --0-687794272-1206542600=:14249 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit > I want to add together numbers in an array with the inject command. I want only the even numbers using only inject. a=[1,2,3,4] a.inject(0) {|x,y| y % 2 == 0 ? x+y : x} => 6 >Second, I need to reverse an array using only the inject command. So, something like above with the result [4,3,2,1] a=[1,2,3,4] a.inject([]) {|x,y| x.unshift(y)} => [4, 3, 2, 1] It seems like an artificial requirement to use only "inject". --0-687794272-1206542600=:14249--