Find Index of SINGLE odd / even number in array So I was doing some challenges on codewars.com and came across the following challenge (I managed to close the browser so could not submit my answer and therefore could not see the best possible solutions).  

Given an array of at least 3 integers, all the elements in the array are either even or oneven EXCEPT for 1 element --> 

[2, 4, 0, 100, 4, 11, 2602, 36]

OR:

[160, 3, 1719, 19, 11, 13, -21]

All the elements are either even or oneven except for one where it is the other way around. Return the element that is the odd one out, so:

findOutlier([2, 4, 0, 100, 4, 11, 2602, 36]) //should return 11

findOutlier([160, 3, 1719, 19, 11, 13, -21]) //should return 160

I got a working solution but there has to be a better way of doing this.. My solution:

function findOutlier(integers){
  let evenCount = 0;
  let oddCount = 0;
  for(let i = 0; i &lt; integers.length; i++) {
    if(integers[i] % 2 === 0) {
      evenCount += 1;
    } else {
      oddCount += 1
    }
  }
  let idx = integers.find(function(index) {
    if(evenCount &gt; 2) {
      return index % 2 === 1
    } else {
      return index % 2 === 0
    }
  })
  return idx
}

```
You only need to iterate the first 3 numbers of the array.

for(let i = 0; i &lt; 3; i++) {


You are iterating through the array twice. You should only iterate once. You can do this by setting the values in the first loop:

let evenCount = 0;
let oddCount = 0;
let evenNumber = 0;
let oddNumber = 0;

for(let i = 0; i &lt; 3; i++) {
    if(integers[i] % 2 === 0) {
      evenCount++;
      evenNumber = integers[i];
    } else {
      oddCount++;
      oddNumber = integers[i];
    }
}

return evenCount &gt; 1 ? oddNumber : evenNumber;