Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve () {
- class Storage {
- constructor (capacity) {
- this.capacity = capacity;
- this.arr = [];
- this.totalCost = 0;
- }
- addProduct (obj) {
- this.arr.push(JSON.stringify(obj));
- this.capacity -= obj.quantity;
- this.totalCost += obj.price * obj.quantity;
- }
- getProducts() {
- const stringified = this.arr.map((item) => JSON.stringify(item));
- let valueToReturn = '';
- stringified.forEach((item) => (valueToReturn === '' ? valueToReturn += `${item}` : valueToReturn += `\n${item}`));
- return valueToReturn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement