declare the map for store each char with occurrence
var mp = { } ; for ( i = 0 ; i < str . length ; i ++ ) if ( mp . hasOwnProperty ( str [ i ] ) ) mp [ str [ i ] ] = mp [ str [ i ] ] + 1 ; else mp [ str [ i ] ] = 1 ;