-
Notifications
You must be signed in to change notification settings - Fork 18
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
Humoud AlGhanim #2
base: main
Are you sure you want to change the base?
Conversation
…chaining in line 33 to work
author: author, | ||
publishedYear: publishedYear, | ||
genre: genre, | ||
}; // replace "{} as Book" with what you see is fit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A fun thing you can do in JS: if the key and the variable share the same name you can do:
return {
title,
author,
publishedYear,
genre
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR made me realise I'm missing an edge condition for this task. I've now made it slightly harder and doubled the size of the test suite 😬
|
||
book.reviews | ||
? book.reviews.push({ reviewer: reviewer, comment: comment }) | ||
: (book.reviews = [{ reviewer: reviewer, comment: comment }]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ternary operators should only really be used as expressions (where the entire ternary operator will be replaced with a value. They should not have side-effects or be used as a general replacement for if statements.
A better ternary use here would be:
const newReview: Review = { reviewer, comment };
book.reviews =
book.reviews ? [...book.reviews, newReview] : [newReview];
No description provided.