From: 7stud -- Date: 2012-09-17T13:52:33+09:00 Subject: Re: Breaking Down the Block def mode(array) freq_for = Hash.new(0) array.each {|number| freq_for[number] += 1} nums_with_frequs = freq_for.sort_by {|key, val| -val} top_count = nums_with_frequs[0][1] most_seen = nums_with_frequs.take_while {|number, freq| freq == top_count} most_seen.map {|number, freq| number} end p mode([10, 10, 10, 20, 30, 30, 40, 40, 40]) --output:-- [10, 40] -- Posted via http://www.ruby-forum.com/.