Advertisement
bebo231312312321

Untitled

Mar 1st, 2023
92
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, curr) => acc + curr.price * curr.quantity, 0);
  9.     }
  10.  
  11.     addProduct(product) {
  12.        this.storage.push(product);    
  13.        this.capacity -= product.quantity;
  14.     }
  15.  
  16.     getProducts() {
  17.         let outputJSON = [];                                                                                                                                              
  18.        this.storage.forEach(prod => {
  19.             outputJSON.push(JSON.stringify(prod));
  20.         });
  21.         return outputJSON.join('\n');
  22.     }
  23.    
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement