dilyana2001

Untitled

Jun 27th, 2021 (edited)
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Storage {
  2.     constructor(capacity) {
  3.         this.capacity = capacity;
  4.         this.storage = [];
  5.     }
  6.  
  7.     get totalCost() {
  8.         return this.storage.reduce((acc, el) => acc + el.price * el.quantity, 0);
  9.     }
  10.  
  11.     addProduct(product) {
  12.         this.storage.push(product);
  13.         this.capacity -= product.quantity;
  14.     }
  15.  
  16.     getProducts() {
  17.         let output = [];
  18.         this.storage.forEach(product => {
  19.             output.push(JSON.stringify(product));
  20.         })
  21.         return output.join('\n');
  22.     }
  23. }
Add Comment
Please, Sign In to add comment