Calculates the
mode
value of the given array.
Mode: The most frequent number—that is, the number that occurs the highest number of times.
Syntax
import { mode } from '@opentf/std';
mode<T>(
arr: T[] = [],
cb?: (val: T, index: number) => number
): number[]
Examples
mode([1]) //=> []
mode([1, 2, 3, 4, 5]) //=> []
mode([4, 2]) //=> []
mode([4, 2, 3, 2, 2]) //=> [2]
mode([0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 4]) //=> [1, 2]
mode([{ n: 1 }, { n: 2 }, { n: 3 }, { n: 2 }], ({ n }) => n) //=> [2]