Number of unique triplets whose XOR is zero | function to count the number of unique triplets whose xor is 0 ; To store values that are present ; stores the count of unique triplets ; traverse for all i , j pairs such that j > i ; xor of a [ i ] and a [ j ] ; if xr of two numbers is present , then increase the count ; returns answer ; Driver code
function countTriplets ( a , n ) { var s = [ ] ; for ( i = 0 ; i < n ; i ++ ) s . push ( a [ i ] ) ; var count = 0 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { var xr = a [ i ] ^ a [ j ] ; if ( s . includes ( xr ) && xr != a [ i ] && xr != a [ j ] ) count ++ ; } } return count / 3 ; } var a = [ 1 , 3 , 5 , 10 , 14 , 15 ] ; var n = a . length ; document . write ( countTriplets ( a , n ) ) ;