title: Javascript sum of arrays and average
body: <p>I have an issue with getting the sum of two arrays and combining their averages while rounding off.</p>
  
  <p>I don't want to hardcode but rather pass two random arrays.  <br/>so here is the code but it keeps returning <strong>NaN</strong></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>function sumAverage(arr) {
    var result = 0;
    // Your code here
    // set an array
    arr = [];
    a = [];
    b = [];
    arr[0] = a;
    arr[1] = b;
  
    var sum = 0;
  
    // compute sum of elements in the array
    for (var j = 0; j &lt; a.length; j++) {
      sum += a[j];
    }
  
    // get the  average of elements in the array
    var total = 0;
    total += sum / a.length;
  
  
    var add = 0;
  
    for (var i = 0; i &lt; b.length; i++)
      add += b[i];
  
    var math = 0;
    math += add / b.length;
  
    result += math + total;
  
    Math.round(result);
  
    return result;
  }
  console.log(sumAverage([
    [2, 3, 4, 5],
    [6, 7, 8, 9]
  ]));</code></pre>
  </div>
  </div>
  </p>