nikolayneykov

Untitled

Mar 5th, 2019
153
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.totalCost = 0;
  5.         this.storage = [];
  6.         this.addProduct = (input) => {
  7.             this.storage.push(input);
  8.             this.capacity -= input.quantity;
  9.             this.totalCost += input.quantity * input.price;
  10.         }
  11.         this.getProducts = () => {
  12.             return this.storage.map(x=>JSON.stringify(x)).join('\n');
  13.         }            
  14.     }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment