Sort a string according to the frequency of characters | Returns count of character in the string ; Check for vowel ; Function to sort the string according to the frequency ; Vector to store the frequency of characters with respective character ; Inserting frequency with respective character in the vector pair ; Sort the vector , this will sort the pair according to the number of characters ; Print the sorted vector content ; Driver Code
function countFrequency ( str , ch ) { var count = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) if ( str [ i ] == ch ) ++ count ; return count ; } function sortArr ( str ) { var n = str . length ; vp = new Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) { vp [ i ] = [ countFrequency ( str , str [ i ] ) , str [ i ] ] ; } vp . sort ( ) ; for ( var i = 0 ; i < n ; i ++ ) document . write ( vp [ i ] [ 1 ] ) ; } let str = " " ; sortArr ( str ) ;