Skip to content

Completed homework#7

Open
tthaman wants to merge 2 commits intofrontend-application-development-uw20:masterfrom
tthaman:completed-homework
Open

Completed homework#7
tthaman wants to merge 2 commits intofrontend-application-development-uw20:masterfrom
tthaman:completed-homework

Conversation

@tthaman
Copy link

@tthaman tthaman commented May 4, 2020

Week 3 HW Submission

Please fill out the information below in order to complete your assignment. Feel free to update this comment later if necessary.

  • Comfort rating on this assignment (1-5): 1|2|3|4|5 4 challenging
  • Completion rating on this assignment: complete|incomplete complete

}

props.data.forEach((rentalObj) => {
rentals.push(
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively you can also use .map. e.g. const rentals = props.data.map(rentalObj => ...)

<div style={{display:'inline-block', fontSize:'12px', paddingBottom:'15px'}}>
<div>{item.title}</div>
<div>${item.cost}</div>
<Button variant={"primary"} onClick={props.removeItem} value={JSON.stringify(item)}>Remove Item</Button>
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting use of using the value attribute on the button. Looks like it works just the same!

removeItem = (e) => {
const rentalObj = JSON.parse(e.target.value);
const updatedObj = [];
this.state.cartItems.forEach(item => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this is a great place to use .filter. e.g. this.state.cartItems.filter(item => item.host !== rentalObj.host)

const cartItems = props.cartItems;

function isInCart(rentalObj) {
let answer = false
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This is a great place to use .some, which returns a boolean when any of the array items matches the condition in the callback. e.g. const answer = cartItems.some(item => item.host === rentalObj.host.name)

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