title: Subtracting 2 dimensional-arrays with a unique id column
body: <p>I'd like to subtract two 2 dimensional-arrays, optionally by placing attention on a "unique id" column.</p>
  
  <p>Also curious about a more description way to say what I'm looking for.</p>
  
  <p>But, for example, given two arrays:</p>
  
  <pre><code>big = [['foo','bar@','baz'],
         ['cat','moew@','purr'],
         ['dog','bark@','woof'],
         ['mew', 'two@', 'blue']]
  
  little = [['foo','bar@','baz'],
            ['dog','moew@','woof'],
            ['dog','bark@','woof']]
  </code></pre>
  
  <p>Then we can subtract them:</p>
  
  <pre><code>big - little #=&gt; [["cat", "moew@", "purr"], ["mew", "two@", "blue"]]
  </code></pre>
  
  <p>Which works because <code>['cat','moew@','purr'] != ['dog','moew@','woof']</code>. However, I'd like those two to be considered equal because they have the same value in the "unique id" column.</p>
  
  <p>This is how I solved it:</p>
  
  <pre><code>big = [['foo','bar@','baz'],
         ['cat','moew@','purr'],
         ['dog','bark@','woof'],
         ['mew', 'two@', 'blue']]
  
  little = [['foo','bar@','baz'],
            ['dog','moew@','woof'],
            ['dog','bark@','woof']]
  
  
  def subtract big, little, key_index=nil
    return big - little unless key_index
    little_keys = little.map { |row| row[key_index] }.flatten
    big.inject([]) do |result, row|
      result &lt;&lt; row unless little_keys.grep(row[key_index]).any?
      result
    end
  end
  
  subtract(big,little) #=&gt; [["cat", "moew@", "purr"], ["mew", "two@", "blue"]]
  subtract(big, little, 1) #=&gt; [["mew", "two@", "blue"]]
  </code></pre>
  
  <p>Am curious to know more about how to describe what I'm trying to do and if there is a better way to do it.</p>
  
  <p>Also, is my way <code>O(n^2)</code> because it's going through the entire array twice? Once for the <code>#inject</code> and once for <code>#grep</code>?</p>