Counting the frequency of all character using Counter function
let freq = new Map ( ) ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( ! freq . has ( s [ i ] ) ) freq . set ( s [ i ] , 0 ) ; freq . set ( s [ i ] , freq . get ( s [ i ] ) + 1 ) ; }