Total no of 1 's in numbers | function to count the frequency of 1. ; driver function
function countDigitOne ( n ) { var countr = 0 ; for ( var i = 1 ; i <= n ; i *= 10 ) { var divider = i * 10 ; countr += parseInt ( n / divider ) * i + Math . min ( Math . max ( n % divider - i + 1 , 0 ) , i ) ; } return countr ; } var n = 13 ; document . write ( countDigitOne ( n ) + " " ) ; n = 113 ; document . write ( countDigitOne ( n ) + " " ) ; n = 205 ; document . write ( countDigitOne ( n ) + " " ) ;