Source: Creating an array of cumulative sum in javascript et demo.