Generate all rotations of a given string | Print all the rotated string . ; Generate all rotations one by one and print ; Current index in str ; Current index in temp ; Copying the second part from the point of rotation . ; Copying the first part from the point of rotation . ; Driver code
function printRotatedString ( str ) { var len = str . length ; var sb ; for ( i = 0 ; i < len ; i ++ ) { sb = [ ] ; var j = i ; var k = 0 ; for ( k2 = j ; k2 < str . length ; k2 ++ ) { sb . push ( str . charAt ( j ) ) ; k ++ ; j ++ ; } j = 0 ; while ( j < i ) { sb . push ( str . charAt ( j ) ) ; j ++ ; k ++ ; } document . write ( sb . join ( " " ) + " " ) ; } } var str = " " ; printRotatedString ( str ) ;