1
var ProductOfNumbers = function () {
2
this.products = [];
3
};
4

5
ProductOfNumbers.prototype.add = function (num) {
6
if (num == 0) {
7
this.products = [];
8
} else {
9
const N = this.products.length;
10
this.products.push(N == 0 ? num : num * this.products[N - 1]);
11
}
12
};
13

14
ProductOfNumbers.prototype.getProduct = function (k) {
15
const N = this.products.length;
16
if (N - k < 0) return 0;
17
if (N == k) return this.products[N - 1];
18
return this.products[N - 1] / this.products[N - k - 1];
19
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0