Find the sum of all possible pairs in an array of N elements | Function to return the sum of the elements of all possible pairs from the array ; To store the required sum ; For every element of the array ; It appears ( 2 * n ) times ; Driver code
function sumPairs ( arr , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum = sum + ( arr [ i ] * ( 2 * n ) ) ; } return sum ; } let arr = [ 1 , 2 , 3 ] ; let n = arr . length ; document . write ( sumPairs ( arr , n ) ) ;