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, el) => acc + el.price * el.quantity, 0);
- }
- addProduct(product) {
- this.storage.push(product);
- this.capacity -= product.quantity;
- }
- getProducts() {
- let output = [];
- this.storage.forEach(product => {
- output.push(JSON.stringify(product));
- })
- return output.join('\n');
- }
- }
Add Comment
Please, Sign In to add comment