Something like:
function mode(values, f) {
const m = new InternMap();
let greatest;
let greatestCount = 0;
for (const v of Array.from(values, f)) {
const count = (m.get(v) || 0) + 1;
if (count > greatestCount) greatestCount = count, greatest = v;
m.set(v, count);
}
return greatest;
}