Skip to content

Comments

Humoud AlGhanim#2

Open
HAlGhanim wants to merge 5 commits intoJoinCODED:mainfrom
HAlGhanim:main
Open

Humoud AlGhanim#2
HAlGhanim wants to merge 5 commits intoJoinCODED:mainfrom
HAlGhanim:main

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