Find array whose elements are XOR of adjacent elements in given array | Function to reconstruct the array arr [ ] with xor of adjacent elements ; Iterate through each element ; Store the xor of current and next element in arr [ i ] ; Function to print the array ; Inputs ; Length of the array given ; Function call to reconstruct the arr [ ] ; Function call to print arr [ ]
function game_with_number ( arr , n ) { for ( let i = 0 ; i < n - 1 ; i ++ ) { arr [ i ] = arr [ i ] ^ arr [ i + 1 ] ; } return arr ; } function print ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } let arr = [ 10 , 11 , 1 , 2 , 3 ] ; let n = arr . length ; let new_arr = game_with_number ( arr , n ) ; print ( new_arr , n ) ;