loading...

re: Daily Challenge #220 - What Dominates Your Array? VIEW POST

FULL DISCUSSION
 

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
code of conduct - report abuse