Phil Mitchell <sentinel_NO_SPAAM / pobox.com> writes:

> 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

You could use #inject under 1.7

Otherwise, I personally tend not to like indexing, so I might write

  intersection, *array_copy = arr_of_arrays
  array_copy.each {|arr| intersection &= arr }

But it depends on the size of arr_of_arrays: I wouldn't to this if it
was likely to be big.


Cheers

Dave