Skip to content

Hannah N#13

Open
hannahwn wants to merge 15 commits intoHackYourAssignment:mainfrom
hannahwn:main
Open

Hannah N#13
hannahwn wants to merge 15 commits intoHackYourAssignment:mainfrom
hannahwn:main

Conversation

@hannahwn
Copy link

Week 6 assingment

@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

@hacdias hacdias assigned hacdias and unassigned hacdias Feb 22, 2026
@reposman33 reposman33 self-assigned this Mar 10, 2026
Copy link

@reposman33 reposman33 left a comment

Choose a reason for hiding this comment

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

Lots of comments, some more important than others. Just sift through it and focus on the array methods. Kudos for elaborate package.json and error checking when reading file.

@@ -0,0 +1,24 @@
{

Choose a reason for hiding this comment

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

Very elaborate package,json file. Good attention to detail!

const content = fs.readFileSync('./books.json', 'utf8');
const books = JSON.parse(content);

if (!Array.isArray(books)) {

Choose a reason for hiding this comment

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

good check...

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

Choose a reason for hiding this comment

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

Better to check first if file exsts - If yes: then read file. Then check if read content is an array. If yes: continue. Else return empty array

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

Choose a reason for hiding this comment

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

fs.readFileSync('./books.json', 'utf8'); can use FILE_NAME too

}
if (error instanceof SyntaxError) {
console.log(
chalk.red(

Choose a reason for hiding this comment

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

Nice to check for specific errors and inform the user

// TODO: Implement this function using map()
const updatedBooks = books.map(function (book) {
if (book.id === id) {
return {

Choose a reason for hiding this comment

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

I saw this elsewhere:
return {...books, read: true}.
Saves writing out a whole new object. You just create a new object from the existing object and overwrite the read property with another value


//Does book exist?

const oldBook = books.find(function (book) {

Choose a reason for hiding this comment

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

books.find(book => book.id === id) does the same because you don't use a function expression (function(book)...). Devs don't use function expressions in array methods

function hasUnreadBooks() {
function hasUnreadBooks(books) {
// TODO: Implement this function using some()
const hasUnread = books.some(function (book) {

Choose a reason for hiding this comment

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

no function(book)... but (book) =>

return;
}

for (let i = 0; i < books.length; i++) {

Choose a reason for hiding this comment

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

books.forEach(book => {const status = book.read ? chalk.green('✓ Read') : chalk.red('○ Unread'))
console.log(...)
}
is less code and does the same


// Count read books
let readCount = 0;
for (let i = 0; i < books.length; i++) {

Choose a reason for hiding this comment

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

const readCount = books.reduce((acc,book) => acc += book.read ? 1 : 0).
Looks a bit complicated but once you get it, it is easier and much less code to remember ('cognitive load')

@reposman33 reposman33 added Reviewed This assignment has been reivewed by a mentor and a feedback has been provided and removed Review in progress labels Mar 10, 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.

3 participants