title: Sort array by frequency instead of the value
body: <p>I am trying to sort the array of letters by their frequency of use. but not getting the correct output. here is my try:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const ar = ['b', 'c', 'a', 'a', 'a', 'e', 'e', 'e', 'e', 'c'];
  
  const re = ar.reduce((ar, l) =&gt; {
    ar[l] ? ar[l]++ : (ar[l] = 1); //finding count of each instance
    return ar;
  }, {});
  
  const vls = [];
  
  for (const [key, val] of Object.entries(re)) {
    for (let i = 0; i &lt; val; i++) {
      vls.push(key); //re creating array by thier count
    }
  }
  
  const sr = vls.sort((a, i) =&gt; (a &lt; i ? 1 : -1)); //not works
  console.log(sr);
  
  //out put should be letters frequecy ['e', 'e', 'e', 'e','a', 'a', 'a','c','c','b]</code></pre>
  </div>
  </div>
  </p>
  <p>Any short and quick way to go?
  Thanks in advance.</p>