DEV Community

Discussion on: Daily Challenge #35 - Find the Outlier

Collapse
 
asg5704 profile image
Alexander Garcia

Not elegant, but it'll do the job.

const findOutlier = (arr) => {
 const firstPass = arr.filter(el => el % 2 === 0)
 const secondPass = arr.filter(el => el % 2 !== 0)

 if(firstPass.length === 1) {
   return firstPass[0]
 }
 return secondPass[0]
}