DEV Community

Discussion on: Daily Challenge #35 - Find the Outlier

Collapse
 
databasesponge profile image
MetaDave 🇪🇺

I have done a Ruby one, based on counting the number of even values in the first three elements of the array to switch the logic between finding the first even and the first odd element.

[
  [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]
].map do |array|
  case array.first(3).select(&:even?).size
    when 1 
      array.find(&:even?)
    else 
      array.find(&:odd?)
  end
end

=> [11, 160, 15, nil]