title: "Find the Parity Outlier Code Wars (Scala)"
body: <p>I am doing some of CodeWars challenges recently and I've got a problem with this one.</p>
  
  <p>"You are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer N. Write a method that takes the array as an argument and returns this "outlier" N."</p>
  
  <p>I've looked at some solutions, that are already on our website, but I want to solve the problem using my own approach.</p>
  
  <p>The main problem in my code, seems to be that it ignores negative numbers even though I've implemented Math.abs() method in scala.</p>
  
  <p>If you have an idea how to get around it, that is more than welcome.</p>
  
  <p>Thanks a lot</p>
  
  <pre><code>object Parity {
  
    var even = 0
    var odd = 0
    var result = 0
  
    def findOutlier(integers: List[Int]): Int = {
  
      for (y &lt;- 0 until integers.length) {
        if (Math.abs(integers(y)) % 2 == 0)
          even += 1
        else
          odd += 1
      }
  
      if (even == 1) {
        for (y &lt;- 0 until integers.length) {
          if (Math.abs(integers(y)) % 2 == 0)
            result = integers(y)
        }
      } else {
        for (y &lt;- 0 until integers.length) {
          if (Math.abs(integers(y)) % 2 != 0)
            result = integers(y)
        }
      }
      result
    }
  </code></pre>