From: Joel VanderWerf Date: 2002-02-27T08:29:54+09:00 Subject: Re: fiddly little array manipulation question Phil Mitchell wrote: > > Is there a nicer way to take the intersection of an array of arrays, other > than: > > intersection = arrOfArrays[0] > for i in 1...arrOfArrays.length > intersection &= arrOfArrays[i] > end > > Am I missing some rubyism? Enumerable#inject helps a little: [ [1,2,3], [2,3,4] ].inject([0,1,2]) { |x, y| x & y } # ==> [2] inject is defined in the pickaxe book, but IIRC it's going to become standard eventually. You can also get it in my enumerable tools package in RAA: http://www.ruby-lang.org/en/raa-list.rhtml?name=Enumerable+tools