Approximation of area under curve using rectangles (Javascript)