I\'m looking for an elegant way of determining which element has the highest occurrence (mode) in a JavaScript array.
For example, in
[\'pear\', \'a
function mode(array){ var set = Array.from(new Set(array)); var counts = set.map(a=>array.filter(b=>b==a).length); var indices = counts.map((a,b)=>Math.max(...counts)===a?b:0).filter(b=>b!==0); var mode = indices.map(a=>set[a]); return mode; }