Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Storage {
- constructor(capacity) {
- this.capacity = capacity;
- this.products = [];
- }
- addProduct(product) {
- this.products.push(product);
- this.capacity -= product.quantity;
- }
- getProducts() {
- return this.products.map(x => JSON.stringify(x)).join('\n');
- }
- get totalCost() {
- return this.products.reduce((x, product) => x + product.price * product.quantity, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement