Conversation
📝 HackYourFuture auto gradeAssignment Score: 0 / 100 ✅Status: ✅ Passed Test Details |
sycons
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Good job generating the id instead of using the one passed in the book parameter ⭐
| } | ||
| return book; | ||
| }); | ||
| if (!found) { |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
Nice touch converting to lower case when comparing strings ⭐
Also a real world scenario that happens often in apps.
No description provided.