title: typescript counting duplicates in array and sorting the result by the count of each item
body: <p>I have an array which is populated based on the values pulled in from an api call.
  the array would be having values like this </p>
  
  <pre><code>["9777", "9777", "2.4", "9777", "2.4", "2.4", "9777", "2.4", "2.4", "9777", "9777", "2.4", "2.4", "2.4"]
  </code></pre>
  
  <p>What I am trying to do is get the count of the occurences of each item in the array and sort it descending based on the count.</p>
  
  <p>I did this which I got it from stackoverflow:</p>
  
  <pre><code>data.forEach(function (x) {
    counts[x] = (counts[x] || 0) + 1;
  });
  </code></pre>
  
  <p>It works, but it gives weird results which makes it difficult to extract the value from the result.
  here are the results:
  <a href="https://i.stack.imgur.com/bKVwT.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bKVwT.jpg" alt="enter image description here"></a></p>