Product of absolute difference of every pair in given Array | Function to return the product of abs diff of all pairs ( x , y ) ; To store product ; Iterate all possible pairs ; Find the product ; Return product ; Given array arr [ ] ; Function Call
function getProduct ( a , n ) { var p = 1 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i + 1 ; j < n ; j ++ ) { p *= Math . abs ( a [ i ] - a [ j ] ) ; } } return p ; } var arr = [ 1 , 2 , 3 , 4 ] ; var N = arr . length ; document . write ( getProduct ( arr , N ) ) ;