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

Favour's PR #2

Open
wants to merge 6 commits into
base: first
Choose a base branch
from
Open

Favour's PR #2

wants to merge 6 commits into from

Conversation

lumiscript
Copy link

Do not merge.. PR created for Code Review purposes

@@ -0,0 +1,17 @@
import React from "react";
import ItemList from "../Item-list/Item-list";
const cart = props => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to support standards, name your components with a starting capital letter so we are able to differentiate between functions and components.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor this to use map instead of for.. break the operation into 2 steps.. the first step should multiply each item price by its quantity and the second step will add up all the items in the array. this can be 2 separate functions chained together.

What i described above is functional programming 101

};

addToCart = (id) => {
const inventoryIndex = this.state.inventory.findIndex(p => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can refactor this operation to be a filter and you return the output of the filter

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

Successfully merging this pull request may close these issues.

2 participants