Replace every element of the array by product of all other elements | Javascript program to Replace every element by the product of all other elements ; Calculate the product of all the elements ; Replace every element product of all other elements ; Driver Code ; Print the modified array .
function ReplaceElements ( arr , n ) { let prod = 1 ; for ( let i = 0 ; i < n ; ++ i ) { prod *= arr [ i ] ; } for ( let i = 0 ; i < n ; ++ i ) { arr [ i ] = parseInt ( prod / arr [ i ] , 10 ) ; } } let arr = [ 2 , 3 , 3 , 5 , 7 ] ; let n = arr . length ; ReplaceElements ( arr , n ) ; for ( let i = 0 ; i < n ; ++ i ) { document . write ( arr [ i ] + " " ) ; }