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(arr){ return arr.reduce(function(counts,key){ var curCount = (counts[key+''] || 0) + 1; counts[key+''] = curCount; if (curCount > counts.max) { counts.max = curCount; counts.mode = key; } return counts; }, {max:0, mode: null}).mode }