Modify a string by performing given shift operations | Function to find the string obtained after performing given shift operations ; If shift [ i ] [ 0 ] = 0 , then left shift Otherwise , right shift ; Stores length of the string ; Effective shift calculation ; Stores modified string ; Right rotation ; Left rotation ; Driver Code
function stringShift ( s , shift ) { var val = 0 ; for ( var i = 0 ; i < shift . length ; ++ i ) val += shift [ i ] [ 0 ] == 0 ? - shift [ i ] [ 1 ] : shift [ i ] [ 1 ] ; var len = s . length ; val = val % len ; var result = " " ; if ( val > 0 ) result = s . substring ( len - val , len ) + s . substring ( 0 , len - val ) ; else result = s . substring ( - val , len ) + s . substring ( 0 , - val ) ; document . write ( result ) ; } var s = " " ; var shift = [ [ 0 , 1 ] , [ 1 , 2 ] ] ; stringShift ( s , shift ) ;