Traverse through array elements and count frequencies
for ( let i = 0 ; i < n ; ++ i ) { if ( mp1 . has ( arr [ i ] ) ) { mp1 . set ( arr [ i ] , mp1 . get ( arr [ i ] ) + 1 ) ; } else { mp1 . set ( arr [ i ] , 1 ) ; } }