Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question (Bug?) "Reducing Complexity Excerise" #7

Open
schaetor opened this issue Feb 10, 2022 · 0 comments
Open

Question (Bug?) "Reducing Complexity Excerise" #7

schaetor opened this issue Feb 10, 2022 · 0 comments

Comments

@schaetor
Copy link

Hi Lukas,

I have an understanding question on the first exercise. I was not sure, where and how to ask ... so I went to github ;).

If I am not mistaken the total price calculated and stored in this.price is different, then the total price of all widgets stored this-widgets?

reCalculateTotal(mode: string, widgets: Widget[], widget: Widget) {
    this.widgets = this.updateWidgets(mode, widgets, widget);
    this.price = this.getTotalPrice(widgets);
  }

What I mean is, we run this.getTotalPrice(widgets), while we store on this.widgets a different collection based on the passed mode.
The total price of that collection should be different to the collection passed on this.getTotalPrice(widgets).

I have modified the function a bit to log the difference.:

 reCalculateTotal(mode: string, widgets: Widget[], widget: Widget) {
   console.log(`calling: this.getTotalPrice(this.updateWidgets(mode, widgets, widget)): ${this.getTotalPrice(this.updateWidgets(mode, widgets, widget))}`);
   console.log(`calling: this.getTotalPrice(widgets): ${this.getTotalPrice(widgets)}`);
   this.widgets = this.updateWidgets(mode, widgets, widget);
   this.price = this.getTotalPrice(widgets);
 }

Log:

PASS micro apps/micro/src/app/home/home.component.spec.ts
 HomeComponent
    should create (69 ms)
    should call updateWidgets and getTotalPrice on reCalculateTotal (35 ms)
 console.log
   calling: this.getTotalPrice(this.updateWidgets(mode, widgets, widget)): 100

     at HomeComponent.reCalculateTotal (src/app/home/home.component.ts:16:13)

 console.log
   calling: this.getTotalPrice(widgets): 0

     at HomeComponent.reCalculateTotal (src/app/home/home.component.ts:17:13)

The total price stored in this.price is 0 while the total price on all widgets stored in this.widgetsis 100.

From my understanding, the total price function getTotalPrice should be executed on the return value of updateWidgets.

I hope, I could make the issue clear.

Best
Torsten

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant