Apply Discount Every n Orders LeetCode solution in JavaScript

1
var Cashier = function (n, discount, products, prices) {
2
this.n = n;
3
this.cc = 0;
4
this.discount = (100 - discount) / 100;
5
this.products = new Map();
6
const len = products.length;
7
for (let i = 0; i < len; i++) {
8
this.products.set(products[i], prices[i]);
9
}
10
};
11

12
Cashier.prototype.getBill = function (product, amount) {
13
let total = 0,
14
len = product.length;
15
for (let i = 0; i < len; i++) {
16
total += amount[i] * this.products.get(product[i]);
17
}
18
this.cc++;
19
if (this.cc % this.n == 0) {
20
total = total * this.discount;
21
this.cc = 0;
22
}
23
return total;
24
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0