title: How do I get the average time from an Array of dates?
body: <p>I'm trying to generate a "changefreq" for an xml sitemap. Each time I save a page I add a date to a "save_history" Array which gives me a list of dates to work with. Initially I thought I would just add up all the dates and divide the the length but that just gives me the average time since 1/1/1970. How can I fix this function to get the average time <em>between</em> the dates?</p>
  
  <p><a href="http://jsfiddle.net/jwerre/pAfdM/19/" rel="nofollow">http://jsfiddle.net/jwerre/pAfdM/19/</a></p>
  
  <p>or</p>
  
  <pre><code>  getChangeFequency = function(history) {
  
      var sum = _.reduce(history, function(memo, num) {
        return memo + num.getTime();
      }, 0);
      var average = sum / history.length;
      var hours = average / 3600000;
  
      console.log("totals:", sum, average, hours); // 20292433147523 1352828876501.5334 375785.7990282037
  
      if (hours &gt; 17532) {
        return "never";
      } else if ((8766 &lt; hours &amp;&amp; hours &gt; 17531)) {
        return "yearly";
      } else if ((730 &lt; hours &amp;&amp; hours &gt; 8765)) {
        return "monthly";
      } else if ((168 &lt; hours &amp;&amp; hours &gt; 729)) {
        return "weekly";
      } else if ((24 &lt; hours &amp;&amp; hours &gt; 167)) {
        return "daily";
      } else if ((1 &lt; hours &amp;&amp; hours &gt; 23)) {
        return "hourly";
      } else {
        return "always";
      }
    };
  
    save_history = [ Tue Nov 13 2012 09:47:39 GMT-0800 (PST), Tue Nov 13 2012 09:47:44 GMT-0800 (PST), Tue Nov 13 2012 09:47:45 GMT-0800 (PST), Tue Nov 13 2012 09:47:46 GMT-0800 (PST), Tue Nov 13 2012 09:47:47 GMT-0800 (PST) ]
  
    getChangeFrequency(save_history)
  </code></pre>