als-statistics
Version:
A powerful and lightweight JavaScript library for descriptive statistics, regression, clustering, outlier detection, and noise analysis using a flexible table/column architecture.
17 lines (15 loc) • 439 B
JavaScript
function mode(values) {
const freq = new Map();
let maxFreq = 0;
for (let num of values) {
const count = (freq.get(num) || 0) + 1;
freq.set(num, count);
if (count > maxFreq) maxFreq = count;
}
const modes = [];
for (const [val, count] of freq.entries()) {
if (count === maxFreq) modes.push(val);
}
return modes.length === values.length ? [] : modes;
}
module.exports = mode