Sum of product of all pairs of a Binary Array | Function to print the sum of product of all pairs of the given array ; Stores count of one in the given array ; If current element is 1 ; Increase count ; Return the sum of product of all pairs ; Driver Code ; Stores the size of the given array
function productSum ( arr , N ) { let cntOne = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 1 ) cntOne ++ ; } return cntOne * ( cntOne - 1 ) / 2 ; } let arr = [ 0 , 1 , 1 , 0 , 1 ] ; let n = arr . length ; document . write ( productSum ( arr , n ) + " " ) ;