Find extra element in the second array | Function to return the extra element in B [ ] ; To store the result ; Find the XOR of all the element of array A [ ] and array B [ ] ; Driver code
function extraElement ( A , B , n ) { let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) ans ^= A [ i ] ; for ( let i = 0 ; i < n + 1 ; i ++ ) ans ^= B [ i ] ; return ans ; } let A = [ 10 , 15 , 5 ] ; let B = [ 10 , 100 , 15 , 5 ] ; let n = A . length ; document . write ( extraElement ( A , B , n ) ) ;