The have this simple function to count letter frequency
function getFreq(str){
  var freq={};
  str.replace(/[a-z A-Z]/g, function(match){
    freq[match] = (freq[match] || 0) + 1;
    return match;
  });
  console.log(JSON.stringify(freq));
  return freq;
  
}<input type="text" onchange="getFreq(this.value);" />Input  sample : Hello World
Output :
{"H":1,"e":1,"l":3,"o":2," ":1,"W":1,"r":1,"d":1}
Expected Output :
{"d":1,"e":1,"l":3,"o":2,"r":1,"H":1,"W":1," ":1}  
----- lower case , then Upper case, whitespaces at last
I tried using console.log(JSON.stringify(freq.sort())); to sort the result but it didn't worked.
 
     
     
    