View Single Post
Old 12-03-2012, 07:43 AM   PM User | #22
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by rnd me View Post
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..
Philip M is offline   Reply With Quote