Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- getInfo() {
- let info = {};
- info.totalPrice = this.showCost();
- info.products = [];
- let names = {};
- for (let i = 0; i < this.products.length; i += 1) {
- if (!names[this.products[i].name]) {
- names[this.products[i].name] = {};
- names[this.products[i].name].price = 0;
- names[this.products[i].name].quantity = 0;
- }
- names[this.products[i].name].price += this.products[i].price;
- names[this.products[i].name].quantity += 1;
- }
- let props = Object.keys(names);
- for (let i = 0; i < props.length; i += 1) {
- info.products.push({
- name: props[i],
- totalPrice: names[props[i]].price,
- quantity: names[props[i]].quantity
- });
- }
- return info;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement