Quote:
Originally Posted by rnd me
is there anything map/filter can't do?
Code:
r=[ 77, 101, 191, 91, 91, 191, 191, 191, 191,343 ]
.map(function(a){return this[a]?(this[a]+=1):(this[a]=1),this;},[])[0]
r.indexOf(Math.max.apply(0,r.filter(Number))); // === 191
|
Yes - report the mode when two values occur the same number of times. Obviously you can have more than one mode.
Having two modes is called "bimodal". More than 2 modes is called "multi-modal".
felgall's and Old Pedant's scripts do this.
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Last edited by Philip M; 12-03-2012 at 07:55 AM..
|