Sum of values of all possible non | Function to return the required sum ; Find the sum of the array elements ; Every element appears 2 ^ ( n - 1 ) times ; Driver code
function sum ( arr , n ) { var sum = 0 ; for ( i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } sum = sum * parseInt ( Math . pow ( 2 , n - 1 ) ) ; return sum ; } var arr = [ 2 , 1 , 5 , 6 ] ; var n = arr . length ; document . write ( sum ( arr , n ) ) ;