Update frequency of A [ i ]
if ( frequency . has ( A [ i ] ) ) frequency . set ( A [ i ] , frequency . get ( A [ i ] ) + 1 ) else frequency . set ( A [ i ] , 1 ) ; } frequency . forEach ( ( value , key ) => {