Modify a matrix by converting each element to XOR of its digits | JavaScript program to implement the above approach ; Function to calculate Bitwise XOR of digits present in X ; Stores the Bitwise XOR ; While X is true ; Update Bitwise XOR of its digits ; Return the result ; Function to print matrix after converting each matrix element to XOR of its digits ; Traverse each row of arr [ ] [ ] ; Traverse each column of arr [ ] [ ] ; Function to convert the given matrix to required XOR matrix ; Traverse each row of arr [ ] [ ] ; Traverse each column of arr [ ] [ ] ; Store the current matrix element ; Find the xor of digits present in X ; Stores the XOR value ; Print resultant matrix ; Driver code
let M = 3 ; let N = 3 ; function findXOR ( X ) { let ans = 0 ; while ( X != 0 ) { ans ^= ( X % 10 ) ; X /= 10 ; } return ans ; } function printXORmatrix ( arr ) { for ( let i = 0 ; i < M ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { document . write ( arr [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } function convertXOR ( arr ) { for ( let i = 0 ; i < M ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { let X = arr [ i ] [ j ] ; let temp = findXOR ( X ) ; arr [ i ] [ j ] = temp ; } } prletXORmatrix ( arr ) ; } let arr = [ [ 27 , 173 , 5 ] , [ 21 , 6 , 624 ] , [ 5 , 321 , 49 ] ] ; convertXOR ( arr ) ; ;