#!/usr/bin/ruby

#
## http://rosettacode.org/wiki/Averages/Mode
#

func mode(array) {
    var c = Hash.new;
    array.each{|i| c{i} := 0 ++};
    var max = c.values.max;
    c.keys.grep{|i| c{i} == max};
}

say mode([1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17]).join(' ');
say mode([1, 1, 2, 4, 4]).join(' ');