sumConstructor.prototype.sumRange = function (i, j) { const { arr, sums } = this; const lastIndex = arr.length - 1; if (i < 0) i = 0; if (j < 0) j = 0; if (i > lastIndex) i = lastIndex; if (j > lastIndex) j = lastIndex; if (!sums.length) { this.sums.push(0); let sum = 0; for (let i = 0; i < arr.length; i++) { sum += arr[i]; this.sums.push(sum); } } returnthis.sums[j + 1] - this.sums[i]; }