Check if an integer is rotation of another given integer | Function to check if the integer A is a rotation of the integer B ; Stores the count of digits in A ; Stores the count of digits in B ; If dig1 not equal to dig2 ; Stores position of first digit ; Stores the first digit ; Rotate the digits of the integer ; If A is equal to B ; If A is equal to the initial value of integer A ; Driver Code
function check ( A , B ) { if ( A == B ) { return 1 ; } let dig1 = Math . floor ( Math . log10 ( A ) + 1 ) ; let dig2 = Math . floor ( Math . log10 ( B ) + 1 ) ; if ( dig1 != dig2 ) { return 0 ; } let temp = A ; while ( true ) { let power = Math . pow ( 10 , dig1 - 1 ) ; let firstdigit = parseInt ( A / power , 10 ) ; A = A - firstdigit * power ; A = A * 10 + firstdigit ; if ( A == B ) { return 1 ; } if ( A == temp ) { return 0 ; } } } let A = 967 , B = 679 ; if ( check ( A , B ) == 1 ) document . write ( " " ) ; else document . write ( " " ) ;