title: Weighted average from an array
body: <p>I have to write the following weighted average formula in JavaScript:</p>
  
  <blockquote>
    <p>Average = (p1*p2*x1 + p3*p4*x2 + ... +p(n-2)*p(n-1)*xn) / (p1*p2 + p3*p4 + ... + p(n-2)p(n-1) )</p>
  </blockquote>
  
  <p>The formula gives the average of <code>x</code> values.</p>
  
  <p>I also have an <code>array</code> populated with <code>n</code> elements in JavaScript:</p>
  
  <pre><code>Array = (p1,p2,x1,p3,p4,x2....)
  </code></pre>
  
  <p>...where <code>pi</code> are the weights and <code>xi</code> the values I want to find the average for.</p>
  
  <p>How can I write the formula using this array?</p>