1var ProductOfNumbers = function () {2this.products = [];3};45ProductOfNumbers.prototype.add = function (num) {6if (num == 0) {7this.products = [];8} else {9const N = this.products.length;10this.products.push(N == 0 ? num : num * this.products[N - 1]);11}12};1314ProductOfNumbers.prototype.getProduct = function (k) {15const N = this.products.length;16if (N - k < 0) return 0;17if (N == k) return this.products[N - 1];18return this.products[N - 1] / this.products[N - k - 1];19};