Skip to content

Shadi A.#1

Open
shmoonwalker wants to merge 4 commits intoHackYourAssignment:mainfrom
shmoonwalker:main
Open

Shadi A.#1
shmoonwalker wants to merge 4 commits intoHackYourAssignment:mainfrom
shmoonwalker:main

Conversation

@shmoonwalker
Copy link

Complete week 6 task

@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

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.

A few comments re: Array methods in readingList.js. Array methods make for short code, easy to read. Use them, otherwise code becomes quickly too complicated to read.

export function loadBooks() {
try {
if (!fs.existsSync(filePath)) {
fs.writeFileSync(filePath, JSON.stringify([], null, 2));

Choose a reason for hiding this comment

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

I would just do JSON.stringify([]). No null or 2


const books = loadBooks();
const duplicate = books.find(
(b) => b.title.toLowerCase() === book.title.toLowerCase()

Choose a reason for hiding this comment

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

do the book.lowerCase() outside the loop because it doesn't change with each iteration;

Don't use find(). find() returns the book with the same title but you are not interested in the book. You only want to know if a book with the same title exists. Use

some(b => b.title === book.title);

some() returns true ("yes, there is a book with the same title as what uou want to add") or false ("no, there is no...")

(b) => b.title.toLowerCase() === book.title.toLowerCase()
);
if (duplicate) {
console.error(chalk.red(`⚠ Book "${book.title}" already exists.`));

Choose a reason for hiding this comment

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

if you use some() you don't have to assign the book to a const duplicate but you can say if(some(b => b.title === book.title) {...}

}

book.id = books.length > 0 ? Math.max(...books.map((b) => b.id)) + 1 : 1;
book.read = book.read ?? false;

Choose a reason for hiding this comment

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

book.read is a boolean, So it is {read: true} or {read:false} (assuming it has a valid value and is not read:'' for example). No need to assign false to read when it is not true or undefined (undefined is a falsy value).

const books = loadBooks();
let found = false;

const updated = books.map((b) => {

Choose a reason for hiding this comment

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

This looks complicated.. maybe

export function markAsRead(id) {
return loadBooks().map(b => b.id === id ? {...b,read: true} : b)
}

works too


# Dependency directories
node_modules/
.env

Choose a reason for hiding this comment

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

You don't have an .env file... so no need to list it here.

@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.

2 participants