title: Cubic Regression (best fit line) in JavaScript
body: <p>I'm having the worst time trying to find a JavaScript code that could allow me to do cubic regressions. Would write it myself, but my understanding of polynomial math is, well, suboptimal.</p>
  
  <p>So, here's what I'm looking for. Given an input of an array of arrays, where the internal array would be [x,y], the function would give me an output in the form of an array with four parameters - [a,b,c,d], where a, b, c, and d are parameters of the equation y = ax^3 + bx^2 + cx + d.</p>
  
  <p>Example:
  Input is an array like this [[2,5],[5,10],[07,15],[12,20],[20,25],[32,30],[50,35]].</p>
  
  <p>Which essentially is the representation of a table:</p>
  
  <pre>
  |    x   |   y    |
  |-----------------|
  |   02   |   05   |
  |   05   |   10   |
  |   07   |   15   |
  |   12   |   20   |
  |   20   |   25   |
  |   32   |   30   |
  |   50   |   35   |
  </pre>
  
  <p>Now, the output would be [0.000575085,-0.058861065,2.183957502,1.127605507]. These are the a, b, c, and d parameters of the cubic function.</p>
  
  <p>(FYI, the output I got by using Excel's LINEST function and running it on the above set of numbers using an array function {1,2,3}).</p>
  
  <p>How could this be done? Huge thanks in advance for any guidance.</p>
  
  <p>Best,
  Tom</p>