Task[edit]
Write a program to find the mode value of a collection.

The case where the collection is empty may be ignored. Care must be taken to handle the case where the mode is non-unique.

If it is not appropriate or possible to support a general collection, use a vector (array), if possible. If it is not appropriate or possible to support an unspecified value type, use integers.

See also
Tasks for calculating statistical measures



in one go
moving (sliding window)
moving (cumulative)

Mean
Arithmetic

Statistics/Basic
Averages/Arithmetic mean
Averages/Pythagorean means


Averages/Simple moving average




Geometric

Averages/Pythagorean means




Harmonic

Averages/Pythagorean means




Quadratic

Averages/Root mean square




Circular

Averages/Mean angle
Averages/Mean time of day




Median

Averages/Median




Mode

Averages/Mode




Standard deviation

Statistics/Basic



Cumulative standard deviation




Procedure mean(Array InArray(1))
 
  Structure MyMean
    Value.i
    Cnt.i
  EndStructure
 
  Protected i, max, found
  Protected NewList MyDatas.MyMean()
 
  Repeat
    found=#False
    ForEach MyDatas()
      If InArray(i)=MyDatas()\Value 
        MyDatas()\Cnt+1
        found=#True
        Break 
      EndIf
    Next 
    If Not found
      AddElement(MyDatas())
      MyDatas()\Value=InArray(i)
      MyDatas()\cnt+1
    EndIf
    If MyDatas()\Cnt>max
      max=MyDatas()\Cnt
    EndIf
    i+1
  Until i>ArraySize(InArray())
 
  ForEach MyDatas()
    If MyDatas()\Cnt=max
      For i=1 To max
        Print(Str(MyDatas()\Value)+" ")
      Next
    EndIf
  Next
EndProcedure