DEV Community

loading...

Discussion on: Daily Challenge #220 - What Dominates Your Array?

Collapse
windeep profile image
windeep

Ruby

def dominator(arr)
  arr.each.with_object(hash = Hash.new(0)) { |value,dict| dict[value] += 1 }
  hash.each { |k,v| return k if 2*v > arr.size}
  -1
end
Forem Open with the Forem app