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.
Parameters
Section titled “Parameters”sorted
Section titled “sorted”number[]
a sample of one or more data points
Returns
Section titled “Returns”number
mode
Throws
Section titled “Throws”if sorted is empty
Example
Section titled “Example”modeSorted([0, 0, 1]); // => 0