DEV Community

Discussion on: Daily Challenge #35 - Find the Outlier

Collapse
 
muhammadhasham profile image
Muhammad Hasham

With JS

function findOutlier(arr){
let checker = {even:[],odd:[]}
arr.forEach((item) => item%2==0 ? checker['even'].push(item) : checker['odd'].push(item));
return checker['even'].length < checker['odd'].length ? checker['even'][0] : checker['odd'][0];
}

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

Explanation:

  1. Using an object which stores even and odd numbers.
  2. just returning the one with less number.