Repdigit Numbers | Function to check if a number is a Repdigit number ; To store previous digit ( Assigning initial value which is less than any digit ) ; Traverse all digits from right to left and check if any digit is smaller than previous . ; Driver code
function isRepdigit ( num , b ) { let prev = - 1 ; while ( num != 0 ) { let digit = num % b ; num = parseInt ( num / b ) ; if ( prev != - 1 && digit != prev ) return false ; prev = digit ; } return true ; } let num = 2000 , base1 = 7 ; if ( isRepdigit ( num , base1 ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }