Count of rotations required to generate a sorted array | Function to return the count of rotations ; Find the smallest element ; Return its index ; If array is not rotated at all ; Driver Code
function countRotation ( arr , n ) { for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] < arr [ i - 1 ] ) { return i ; } } return 0 ; } let arr1 = [ 4 , 5 , 1 , 2 , 3 ] ; document . write ( countRotation ( arr1 , arr1 . length ) ) ;