View Single Post
Old 12-01-2012, 09:08 PM   PM User | #6
007julien
Regular Coder

 
Join Date: May 2012
Location: France
Posts: 115
Thanks: 0
Thanked 17 Times in 15 Posts
007julien is an unknown quantity at this point
I propose this two lines script with a backreference regular expression
Code:
<script type="text/javascript">
//array to test
var arr=[1,41,222,33,40,18,22,41,2,2,41,42,27,41,58];

var lgt=0,nmb='',str=arr.sort().join(',').replace(/(,\d+)(\1+)/g,
	function(a,b){var m;if (lgt<(m=a.length/b.length)) {lgt=m;nmb=b.substr(1)}});
alert('This number '+nmb+' appaers '+lgt+' times');	

</script>

Last edited by 007julien; 12-01-2012 at 09:11 PM..
007julien is offline   Reply With Quote