Skip to content

Mareh A.#15

Open
mareh-aboghanem wants to merge 1 commit intoHackYourAssignment:mainfrom
mareh-aboghanem:main
Open

Mareh A.#15
mareh-aboghanem wants to merge 1 commit intoHackYourAssignment:mainfrom
mareh-aboghanem:main

Conversation

@mareh-aboghanem
Copy link

No description provided.

@github-actions
Copy link

📝 HackYourFuture auto grade

Assignment Score: 0 / 100 ✅

Status: ✅ Passed
Minimum score to pass: 0
🧪 The auto grade is experimental and still being improved

Test Details

@sycons sycons self-assigned this Feb 21, 2026
Copy link

@sycons sycons left a comment

Choose a reason for hiding this comment

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

Good job! You did the assignment well and showed understanding of the concepts. ⭐

  • Setup & Configuration ✅
  • Data Structure ✅
  • Required Functions ✅
  • Error Handling ✅
  • Display (Chalk) ✅

const booksPath = path.join(__dirname, 'books.json');

function loadBooks() {
// TODO: Implement this function
Copy link

@sycons sycons Feb 22, 2026

Choose a reason for hiding this comment

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

It's good practice to remove TODO comments after you've implemented them. Keeps the code cleaner and shows more clearly the requirement has been implemented.

// Handle invalid JSON (notify user, use empty array)
// Use try-catch for error handling
try{
const readBooks = fs.readFileSync(booksPath, 'utf8');
Copy link

Choose a reason for hiding this comment

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

Pay attention to indenting code. This increases readability.

try{
const books = loadBooks();
const isDuplicate = books.some(existingBook => existingBook.title.toLowerCase() === book.title.toLowerCase());
if (isDuplicate) {
Copy link

Choose a reason for hiding this comment

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

Great job thinking of duplicate book being added ⭐
This is actually a real world scenario that needs to be accounted for in many apps. This shows your thinking about the data stored.

}
// Generate new ID
const lastBook = books[books.length - 1];
const newId = lastBook ? lastBook.id + 1 : 1;
Copy link

Choose a reason for hiding this comment

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

Good job generating the id instead of using the one passed in the book parameter ⭐

}
return book;
});
if (!found) {
Copy link

Choose a reason for hiding this comment

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

Good job checking the book exists for the given id and returning an informative message ⭐
This is often needed in many real world apps.

// Check for duplicate title using some()
try{
const books = loadBooks();
const isDuplicate = books.some(existingBook => existingBook.title.toLowerCase() === book.title.toLowerCase());
Copy link

Choose a reason for hiding this comment

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

Nice touch converting to lower case when comparing strings ⭐
Also a real world scenario that happens often in apps.

@sycons sycons added Reviewed This assignment has been reivewed by a mentor and a feedback has been provided and removed To review labels Feb 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed This assignment has been reivewed by a mentor and a feedback has been provided

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants