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

Humoud AlGhanim #2

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Humoud AlGhanim #2

wants to merge 5 commits into from

Conversation

HAlGhanim
Copy link

No description provided.

author: author,
publishedYear: publishedYear,
genre: genre,
}; // replace "{} as Book" with what you see is fit
Copy link
Contributor

@Octowl Octowl Mar 9, 2025

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
};

Copy link
Contributor

@Octowl Octowl left a 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 }]);
Copy link
Contributor

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];

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