Check if product of array containing prime numbers is a perfect square | Function that returns true if the product of all the array elements is a perfect square ; Update the frequencies of all the array elements ; If frequency of some element in the array is odd ; Driver code
function isPerfectSquare ( arr , n ) { let umap = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { umap [ arr [ i ] ] ++ ; if ( umap . has ( arr [ i ] ) ) { umap . set ( arr [ i ] , umap . get ( arr [ i ] ) + 1 ) } else { umap . set ( arr [ i ] , 1 ) } } for ( let itr of umap ) if ( ( itr [ 1 ] ) % 2 == 1 ) return false ; return true ; } let arr = [ 2 , 2 , 7 , 7 ] ; let n = arr . length ; if ( isPerfectSquare ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;