/**
 * Calculates the mode of an array
 * @param input - array containing values.
 * @returns mode.
 */
export function xMode(input) {
    if (input.length === 0) {
        throw new TypeError('input must not be empty');
    }
    let maxValue = 0;
    let maxCount = 0;
    let count = 0;
    const counts = {};
    for (const element of input) {
        count = counts[element];
        if (count) {
            counts[element]++;
            count++;
        }
        else {
            counts[element] = 1;
            count = 1;
        }
        if (count > maxCount) {
            maxCount = count;
            maxValue = element;
        }
    }
    return maxValue;
}
//# sourceMappingURL=xMode.js.map