mode
mode(
x):number
Defined in: src/mode.js:23
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 sorts its input, so a
tie resolves to the smallest of the tied values regardless of the order they
appeared in. 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 log(n)) because it needs to sort the array internally
before running an O(n) search to find the mode.
Parameters
Section titled “Parameters”number[]
input
Returns
Section titled “Returns”number
mode
Example
Section titled “Example”mode([0, 0, 1]); // => 0