title: How can I rank to the top 20 combinations in a Json Array of objects using Angular?
body: <p>I have a Json array of objects listing pizza order toppings. I would like to use Angular to output the 20 most common order combinations of toppings and rank them from 1-20. So far I have only been able to to use a basic sample array (not my json array of objects) to output the number of occurrences in an array and output them in javascript. (A far cry I know) How can I achieve this or at least get a good start in the right direction?</p>
  
  <p>Json Array of objects that I want this to work for</p>
  
  <pre><code>//it is much bigger than this but shortened it for brevity 
  [{
          "toppings": [
              "pepperoni"
          ]
      },
      {
          "toppings": [
              "feta cheese"
          ]
      },
      {
          "toppings": [
              "pepperoni"
          ]
      },
      {
          "toppings": [
              "bacon"
          ]
      },
      {
          "toppings": [
              "sausage",
              "beef"
          ]
      }
  ]
  </code></pre>
  
  <p>Non json and very basic array that i've got a good start on</p>
  
  <pre><code>var arr = [2, 2, 2, 2, 2, 4, 5, 5, 5, 9];
  
  function foo(arr) {
      var a = [], b = [], prev;
  
      arr.sort();
      for ( var i = 0; i &lt; arr.length; i++ ) {
          if ( arr[i] !== prev ) {
              a.push(arr[i]);
              b.push(1);
          } else {
              b[b.length-1]++;
          }
          prev = arr[i];
      }
  
      return [a, b];
  }
  
  var result = foo(arr);
  document.write('[' + result[0] + ']&lt;br&gt;[' + result[1] + ']')   
  //currently writes [2,4,5,9] [5,1,3,1] 2 appears 5 times , 4 appears 1 time etc.
  </code></pre>
  
  <p>In summation I would like to have an output with Ngfor that loops through the occurrences array ie( In my 2nd example the variable letter b <code>[5,1,3,1]</code>)  and the original json array of objects ( the nested array at the top of the page ) and maps the two together to rank them from most to least. Any help will be appreciated.  </p>