DEV Community

Discussion on: Daily Challenge #35 - Find the Outlier

Collapse
 
easyaspython profile image
Dane Hillard

I believe this would fail if the outlier is even and the rest are an odd number of odd numbers. The examples all have an even number of odd numbers. Can you check that?

Collapse
 
tanguyandreani profile image
Tanguy Andreani

It seems that I can’t make it right and as simple as it was. So I’ll stick with this solution:

def findOutlier numbers
  if numbers.first(3).count(&:even?) > 1
    numbers.find(&:odd?)
  else
    numbers.find(&:even?)
  end
end

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