Replace every element of the array with BitWise XOR of all other | Function to replace the elements ; Calculate the xor of all the elements ; Replace every element by the xor of all other elements ; Driver code ; Print the modified array .
function ReplaceElements ( arr , n ) { let X = 0 ; for ( let i = 0 ; i < n ; ++ i ) { X ^= arr [ i ] ; } for ( let i = 0 ; i < n ; ++ i ) { arr [ i ] = X ^ arr [ i ] ; } } let arr = [ 2 , 3 , 3 , 5 , 5 ] ; let n = arr . length ; ReplaceElements ( arr , n ) ; for ( let i = 0 ; i < n ; ++ i ) { document . write ( arr [ i ] + " " ) ; }