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