XOR of every element of an Array with a given number K | Function to construct new array ; Traverse the array and compute XOR with K ; Print new array ; Driver code
function constructXORArray ( A , n , K ) { let B = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) B [ i ] = A [ i ] ^ K ; for ( let i = 0 ; i < n ; i ++ ) document . write ( B [ i ] + " " ) ; document . write ( " " ) } let A = [ 2 , 4 , 1 , 3 , 5 ] ; let K = 5 ; let n = A . length ; constructXORArray ( A , n , K ) ; let B = [ 4 , 75 , 45 , 42 ] ; K = 2 ; n = B . length ; constructXORArray ( B , n , K ) ;