Digitally balanced numbers | Function to check if the digits in the number is the same number of digits ; Loop to iterate over the digits of the number N ; Loop to iterate over the map ; Driver Code ; function to check
function checkSame ( n , b ) { var m = { } ; while ( n != 0 ) { var r = n % b ; n = n / b ; if ( r in m ) m [ r ] += 1 else m [ r ] = 1 } var last = - 1 ; for ( var i in m ) { if ( last != - 1 && m [ i ] != last ) { return false ; } else { last = m [ i ] ; } } return true ; } var n = 9 ; var base = 2 ; if ( checkSame ( n , base ) ) document . write ( " " ) ; else document . write ( " " ) ;