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

TOP OF THREAD FULL DISCUSSION
re: There's a potential bug. -21 will fail both isOdd and isEven function. The function isOdd should be const isOdd = n => n % 2 !== 0 Since...
 

Whoa.... you've just caught years worth of bugs I have possibly created... 😅

Thank you @Hao for finding the issue. 😀
I really didn't think that thru. 👍

Here is the updated code

let isEven = n => n % 2 === 0
let isOdd = n => n % 2 !== 0
const findOutlier = arr => {
    const odds = arr.filter(isOdd)
    const evens = arr.filter(isEven)
    return odds.length < evens.length ? odds[0] : evens[0]
}
[
  [2, 4, 0, 100, 4, 11, 2602, 36],
  [160, 3, 1719, 19, 11, 13, -21],
  [4, 8, 15, 16, 24, 42],
  [16, 6, 40, 66, 68, 28],
  [-21, 1, 2, 3]
].map(findOutlier)

updated result

I think I would probably use !isEven next time 😎

code of conduct - report abuse