text: Check if two arrays are permutations of each other using Mathematical Operation | Function to check if arrays are permutations of each other . ; Calculating sum and multiply of first array ; Calculating sum and multiply of second array ; If sum and mul of both arrays are equal , return true , else return false . ; Driver code
code: function arePermutations ( a , b , n , m ) { let sum1 = 0 , sum2 = 0 , mul1 = 1 , mul2 = 1 ; for ( let i = 0 ; i < n ; i ++ ) { sum1 += a [ i ] ; mul1 *= a [ i ] ; } for ( let i = 0 ; i < m ; i ++ ) { sum2 += b [ i ] ; mul2 *= b [ i ] ; } return ( ( sum1 == sum2 ) && ( mul1 == mul2 ) ) ; } let a = [ 1 , 3 , 2 ] ; let b = [ 3 , 1 , 2 ] ; let n = a . length ; let m = b . length ; if ( arePermutations ( a , b , n , m ) == true ) document . write ( " " ) ; else document . write ( " " ) ;