Left Rotation and Right Rotation of a String | Function that rotates s towards left by d ; Function that rotates s towards right by d ; Driver code
function leftrotate ( str , d ) { var ans = str . substring ( d , str . length ) + str . substring ( 0 , d ) ; return ans ; } function rightrotate ( str , d ) { return leftrotate ( str , str . length - d ) ; } var str1 = " " ; document . write ( leftrotate ( str1 , 2 ) + " " ) ; var str2 = " " ; document . write ( rightrotate ( str2 , 2 ) + " " ) ;