On 26 Feb 2002 22:58:43 GMT, Phil Mitchell <sentinel_NO_SPAAM / pobox.com> 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?

Well, if you have inject defined, it's semi nice ...


arys = [ [1, 2], [2, 3], [2, 4] ]

class Array
  def inject (n)
    each { | value | n = yield(n, value) }
    n
  end
end

p arys.inject(arys[0]) { | int, each | int & each }

Let's see what other folks offer ...

Ronald E Jeffries
http://www.XProgramming.com
http://www.objectmentor.com
I'm giving the best advice I have. You get to decide whether it's true for you.