Apply Discount Every n Orders LeetCode solution in JavaScript
1var Cashier = function (n, discount, products, prices) {2this.n = n;3this.cc = 0;4this.discount = (100 - discount) / 100;5this.products = new Map();6const len = products.length;7for (let i = 0; i < len; i++) {8this.products.set(products[i], prices[i]);9}10};1112Cashier.prototype.getBill = function (product, amount) {13let total = 0,14len = product.length;15for (let i = 0; i < len; i++) {16total += amount[i] * this.products.get(product[i]);17}18this.cc++;19if (this.cc % this.n == 0) {20total = total * this.discount;21this.cc = 0;22}23return total;24};