3 # This file is part of NIT ( http://www.nitlanguage.org ).
4 # This program is public domain
6 # Task: Arithmetic mode
7 # SEE: <http://rosettacode.org/wiki/Averages/Mode>
10 # Computes the mode or the `array` values.
12 # FIXME: Only the first mode will be returned, should we return an array of modes?
13 fun mode
(array
: Array[Int]): nullable Int do
14 var seen
= new HashMap[Int, Int]
16 if not seen
.has_key
(i
) then seen
[i
] = 0
30 print mode
([1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17]) or else "null"
31 print mode
([1, 1, 2, 4, 4]) or else "null"
32 print mode
([1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17]) or else "null"
33 print mode
([1, 1, 2, 4, 4]) or else "null"