Find the XOR of first half and second half elements of an array | Function to find the xor of the first half elements and second half elements of an array ; xor of elements in FirstHalfXOR ; xor of elements in SecondHalfXOR ; Driver Code ; Function call
function XOROfElements ( arr , n ) { var FirstHalfXOR = 0 ; var SecondHalfXOR = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( i < parseInt ( n / 2 ) ) FirstHalfXOR ^= arr [ i ] ; else SecondHalfXOR ^= arr [ i ] ; } document . write ( FirstHalfXOR + " " + SecondHalfXOR + " " ) ; } var arr = [ 20 , 30 , 50 , 10 , 55 , 15 , 42 ] ; var N = arr . length ; XOROfElements ( arr , N ) ;