Number whose XOR sum with given array is a given number k | This function returns the number to be inserted in the given array ; initialise the answer with k ; XOR of all elements in the array ; Driver Code
function findEletobeInserted ( A , n , k ) { var ans = k ; for ( var i = 0 ; i < n ; i ++ ) ans ^= A [ i ] ; return ans ; } var A = [ 1 , 2 , 3 , 4 , 5 ] ; var n = A . length ; var k = 10 ; document . write ( findEletobeInserted ( A , n , k ) + " " + " " + " " + k ) ;