Modify given string such that odd and even indices is lexicographically largest and smallest | Function to modify the given string satisfying the given criteria ; Traverse the string S ; If i is even ; If the S [ i ] is ' a ' , then change S [ i ] to ' b ' ; Otherwise , change S [ i ] to ' a ' ; If S [ i ] is ' z ' , then change S [ i ] to ' y ' ; Otherwise , change S [ i ] to ' z ' ; Return the result ; Driver Code
function performOperation ( S , N ) { for ( var i = 0 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { if ( S . charAt ( i ) == ' ' ) { S [ i ] = ' ' ; } else { S [ i ] = ' ' ; } } else { if ( S . charAt ( i ) == ' ' ) { S . charAt ( i ) = ' ' ; } else { S [ i ] = ' ' ; } } } return S ; } var S = " " ; var N = S . length ; document . write ( performOperation ( S , N ) ) ;