Maximum value possible by rotating digits of a given number | Function to find the maximum value possible by rotations of digits of N ; Store the required result ; Store the number of digits ; Iterate over the range [ 1 , len - 1 ] ; Store the unit 's digit ; Store the remaining number ; Find the next rotation ; If the current rotation is greater than the overall answer , then update answer ; Print the result ; Driver Code
function findLargestRotation ( num ) { let ans = num ; let len = Math . floor ( Math . log10 ( num ) + 1 ) ; let x = Math . pow ( 10 , len - 1 ) ; for ( let i = 1 ; i < len ; i ++ ) { let lastDigit = num % 10 ; num = parseInt ( num / 10 ) ; num += ( lastDigit * x ) ; if ( num > ans ) { ans = num ; } } document . write ( ans ) ; } let N = 657 ; findLargestRotation ( N ) ;