Advertisement
ErolKZ

Untitled

Oct 31st, 2021
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1.  
  2.  
  3. class Storage {
  4.  
  5. constructor (capacity) {
  6.  
  7. this.capacity = capacity;
  8.  
  9. this.arr = [];
  10.  
  11. this.totalCost = 0;
  12.  
  13. }
  14.  
  15.  
  16. addProduct (obj) {
  17.  
  18. this.arr.push(obj);
  19.  
  20. this.capacity -= obj.quantity;
  21.  
  22. this.totalCost += obj.price * obj.quantity;
  23.  
  24. }
  25.  
  26. getProducts() {
  27.  
  28. const stringified = this.arr.map((item) => JSON.stringify(item));
  29.  
  30. let valueToReturn = '';
  31.  
  32. stringified.forEach((item) => (valueToReturn === '' ? valueToReturn += `${item}` : valueToReturn += `\n${item}`));
  33.  
  34. return valueToReturn;
  35.  
  36. }
  37.  
  38.  
  39.  
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement