Sum of all ordered pair | Function to calculate the sum of all pair - products ; Stores sum of array ; Update sum of the array ; Driver Code
function sumOfProd ( arr , N ) { let sum = 0 ; for ( let i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } return sum * sum ; } let arr = [ 2 , 3 , 1 , 5 , 4 ] ; let N = arr . length ; document . write ( sumOfProd ( arr , N ) ) ;