#!/usr/bin/ruby

# Translation of: http://rosettacode.org/wiki/Averages/Mode#Perl

func mode (a) {

    var m = Hash.new;
    a.each { |i|
        m{i} := 0 ++;
    }

    var best = m.values.max;
    m.keys.grep { m{_} == best };
};

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