How do I find the mode of an array?

Hey everyone!

I’m having trouble finding the mode of an array. Median and mean are there, but mode for some reason doesn’t work as intended.

[1, 2, 2, 2, 2, 3, 4, 5, 2, 2].mode;

I get an error when I run that code.

I appreciate your help.

SequenceableCollection>>mode rotates and transposes a scale, i.e.

[0, 2, 4, 5, 7, 9, 11].mode(5, 12) == [0, 2, 3, 5, 7, 8, 10]

I’m not sure if the statistical mode is in the standard libraries or not, perhaps:

+ SequenceableCollection {
    mostCommonItem {
        ^this.asSet.collect({ arg i; this.occurrencesOf(i) -> i }).maxItem.value
    }
}

[1, 2, 2, 3, 4, 5].mostCommonItem == 2
[1, 1, 2, 2, 3, 3].mostCommonItem == 1

That worked like a charm! Thanks a million