Maximum Sum of Products of Two Arrays | Function that calculates maximum sum of products of two arrays ; Variable to store the sum of products of array elements ; length of the arrays ; Sorting both the arrays ; Traversing both the arrays and calculating sum of product ; Driver code
function maximumSOP ( a , b ) { let sop = 0 ; let n = a . length ; a . sort ( ) ; b . sort ( ) ; for ( let i = 0 ; i < n ; i ++ ) { sop += ( a [ i ] * b [ i ] ) ; } return sop ; } let A = [ 1 , 2 , 3 ] ; let B = [ 4 , 5 , 1 ] ; document . write ( maximumSOP ( A , B ) ) ;