Skip to content

modeSorted

modeSorted(sorted): number

Defined in: src/mode_sorted.js:20

The mode is the number that appears in a list the highest number of times. There can be multiple modes in a list. This algorithm expects sorted input, so equal values are adjacent and a tie resolves to the smallest of the tied values. modeFast breaks ties differently, returning whichever tied value reaches the highest count first.

This is a measure of central tendency: a method of finding a typical or central value of a set of numbers.

This runs in O(n) because the input is sorted.

number[]

a sample of one or more data points

number

mode

if sorted is empty

modeSorted([0, 0, 1]); // => 0