title: how to find mean and variance using reduce()?
body: <p>I wrote a function which returns mean and variance of the given list using only reduce().</p>
  
  <pre><code>    var list = [1, 2, 3, 4];
  
      var math = getMeanAndVar(list);
  
      function getMeanAndVar(list) {
  
          var res = list.reduce(function(lis, cur, ind, arr) {
  
              var meanTot = arr.reduce(function(pre, cur) {
                  return pre + cur;
              })
              var total = getVariance(arr, tot / arr.length);
              return {
                  mean: meanTot / arr.length,
                  variance: total / arr.length
              }
  
              function getVariance(list, mean) {
                  return list.reduce(function(pre, cur) {
                      pre = pre + Math.pow((cur - mean), 2);
                      return pre;
                  }, 0)
              }
          })
          return ["Mean:",
              res.mean,
              "Variance:",
              res.variance
          ].join(' ');
      }
  console.log(math);
  </code></pre>
  
  <p>Is there any other way to optimize the code?</p>