1
var Fancy = function () {5
this.modulo = Math.pow(10, 9) + 7;12
Fancy.prototype.append = function (val) {13
this.sequence.push(val);14
this.appliedOps.push(this.ops.length);21
Fancy.prototype.addAll = function (inc) {22
this.ops.push(["add", inc]);29
Fancy.prototype.multAll = function (m) {30
this.ops.push(["mult", m]);37
Fancy.prototype.getIndex = function (idx) {38
if (idx >= this.sequence.length) {42
while (this.appliedOps[idx] < this.ops.length) {43
const [operation, value] = this.ops[this.appliedOps[idx]];44
this.appliedOps[idx]++;46
if (operation === "mult") {47
this.sequence[idx] = (this.sequence[idx] * value) % this.modulo;50
if (operation === "add") {51
this.sequence[idx] = (this.sequence[idx] + value) % this.modulo;55
return this.sequence[idx];59
* Your Fancy object will be instantiated and called as such:60
* var obj = new Fancy()64
* var param_4 = obj.getIndex(idx)