title: Sorting array of arrays based on means
body: <p>I just finished taking a coding assessment and had trouble with sorting an array of arrays by their means. Each group should contain a set of indices(i,j,etc.) such that the corresponding arrays all (<code>a[i]</code>,<code>a[j]</code>,etc.) all have the same mean.</p>
  <p>For example:</p>
  <pre class="lang-js prettyprint-override"><code>let a = [[3,3,4,2],
           [4,4],
           [4,0,3,5],
           [3,3]
         ]
  function sortMean(a) {
  let newArr = a.sort(function (a, b) {
    let sum1 = a.reduce(function (c, d) {
      return c + d;
    });
    let sum2 = b.reduce(function (c, d) {
      return c + d;
    });
  
    let mean1 = sum1 / a.length;
    let mean2 = sum2 / b.length;
    return mean1 - mean2;
  });
  
  sortMean(a)
  expected output: [[0,2,3],[1]]
  
  </code></pre>
  <p>So far I am able to sort by their means, but am having issues with grouping them into arrays and their indicies.</p>