Loop to compute the frequency
for ( var i = 0 ; i < n ; i ++ ) if ( frequency . has ( a [ i ] ) ) { frequency . set ( a [ i ] , frequency . get ( a [ i ] ) + 1 ) ; } else { frequency . set ( a [ i ] , 1 ) ; }