Reverse string without using any temporary variable | Function to reverse string and return revesed string ; Iterate loop upto start not equal to end ; XOR for swapping the variable ; Driver Code
function reversingString ( str , start , end ) { while ( start < end ) { str [ start ] = String . fromCharCode ( str [ start ] . charCodeAt ( 0 ) ^ str [ end ] . charCodeAt ( 0 ) ) ; str [ end ] = String . fromCharCode ( str [ end ] . charCodeAt ( 0 ) ^ str [ start ] . charCodeAt ( 0 ) ) ; str [ start ] = String . fromCharCode ( str [ start ] . charCodeAt ( 0 ) ^ str [ end ] . charCodeAt ( 0 ) ) ; ++ start ; -- end ; } return ( str ) . join ( " " ) ; } let s = " " ; document . write ( reversingString ( s . split ( " " ) , 0 , 12 ) ) ;