Product of non | Function to find the product of all non - repeated elements in an array ; sort all elements of array ; Driver code
function findProduct ( arr , n ) { arr . sort ( ) ; var prod = 1 * arr [ 0 ] ; for ( i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] != arr [ i + 1 ] ) { prod = prod * arr [ i + 1 ] ; } } return prod ; } var arr = [ 1 , 2 , 3 , 1 , 1 , 4 , 5 , 6 ] ; var n = arr . length ; document . write ( findProduct ( arr , n ) ) ;