re: Daily Challenge #35 - Find the Outlier VIEW POST

FULL DISCUSSION
 

This is the shortest solution I can create.

const isEven = n => n%2 === 0
const isOdd = n => n%2 > 0

const findOutlier = (arr) => {
  const evenArr = arr.filter(isEven)
  const oddArr = arr.filter(isOdd)

  return evenArr > oddArr ? oddArr[0] : evenArr[0]
}

console.log(findOutlier([2, 4, 0, 100, 4, 11, 2602, 36]))
console.log(findOutlier([160, 3, 1719, 19, 11, 13, -21]))
console.log(findOutlier([4, 8, 15, 16, 24, 42] ))
console.log(findOutlier([16, 6, 40, 66, 68, 28]))

code of conduct - report abuse