title: Remove duplicates from a multi-dimensional array
body: <p>I wrote the following extension to remove duplicates from my Array. </p>
  
  <pre><code>extension Array where Element : Equatable{
  
      func removeDups() -&gt; [Element]{
          var result = [Element]()
  
          for element in self{
              if !result.contains(element){
                  result.append(element)
              }
          }
  
          return result
      }
  }
  </code></pre>
  
  <p><strong>Linear Array</strong></p>
  
  <pre><code>let linearArr = [1,2,2,3]
  linearArr.removeDups() // [1,2,3] works well!
  </code></pre>
  
  <p><strong>Multi dimensional Array</strong></p>
  
  <pre><code>let multiDimArr : [[Int]] = [[1,2,3], [1,2,3], [1,2 ,4]]
  multiDimArr.removeDups() // Error!
  </code></pre>
  
  <blockquote>
    <p>Type [Int] does not conform to Equatable</p>
  </blockquote>
  
  <p>I read <a href="https://stackoverflow.com/a/27568162/5175709">here</a>. And the answer says Array comparisons using <code>==</code> should work. It doesn't work all the time:</p>
  
  <p><strong>Works</strong></p>
  
  <pre><code>if (["1", "2"] == ["1", "2"]){
      print("true")
  }
  </code></pre>
  
  <p><strong>Doesn't work</strong></p>
  
  <pre><code>if ([1, 2] == [1, 2]){ // ERROR!
      print("true")
  }
  </code></pre>
  
  <blockquote>
    <p>Ambiguous use of operator '==' </p>
  </blockquote>
  
  <p>This is peculiar. I can compare Array of <code>String</code>s but can't compare Array of <code>Int</code>s.</p>
  
  <p>I also saw <a href="https://stackoverflow.com/questions/27567736/compare-arrays-in-swift/27568162#comment43574159_27568162">this comment</a>: </p>
  
  <p><em>The reason <code>myArray1 == myArray2</code> is that <code>NSObject</code> conforms to Equatable, calling <code>-[equals:]</code> to conduct the test</em></p>
  
  <p>Not sure if the ☝️ comment is still valid. </p>
  
  <p>To summarize:</p>
  
  <ul>
  <li>Are arrays equatable? Can I compare them using <code>==</code></li>
  <li>Why is it different for comparing Array of <code>String</code>s vs. Array of <code>Int</code>s</li>
  <li>How can I remove duplicates from a multi-dimensional array?</li>
  </ul>
  
  <p>I'm currently working with <code>Swift 4.0.2</code></p>