Advertisement
ErolKZ

Untitled

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