Check if all the digits of the given number are same | JavaScript program for the above approach Function to check if all the digits in the number N is the same or not ; Get the length of N ; Form the number M of the type K * 111. . . where K is the rightmost digit of N ; Check if the numbers are equal ; Otherwise ; Driver Code
function checkSameDigits ( N ) { var length = ( Math . log10 ( N ) ) + 1 ; var M = ( Math . pow ( 10 , length ) - 1 ) / ( 10 - 1 ) ; M *= N % 10 ; if ( M = N ) return " " ; return " " ; } var N = 222 ; document . write ( checkSameDigits ( N ) ) ;