Build a Book Organizer - Build a Book Organizer

Tell us what’s happening:

The result of log could represent an array of sorted objects.
But I could not pass the last test.

Your code so far

let books = [
  {
    title: "Designing Your Life",
    authorName: "Bill Burnett and Dave Evans",
    releaseYear: 2016,
  },
  {
    title: "Skills for Succes",
    authorName: "Stella Cottrell",
    releaseYear: 2015,
  },
  {
    title: "How To Prove It",
    authorName: "Daniel J. Velleman",
    releaseYear: 2019,
  },
  {
    title: "Older Story",
    authorName: "Older Author",
    releaseYear: 1940,
  },
  {
    title: "Old Story",
    authorName: "Old Author",
    releaseYear: 1960,
  },
  {
    title: "The Same Old Story",
    authorName: "Same Old Author",
    releaseYear: 1960,
  },
];

const sortByYear = (bk1, bk2) => {
  if (bk1.releaseYear < bk2.releaseYear) {
    return -1;
  } else if (bk1.releaseYear > bk2.releaseYear) {
    return 1;
  } else {
    return 0;
  }
};

let filteredBooks = [];

let filterBooksByYear = (year) => {
  return books.filter((bk) => bk.releaseYear > year);
};

filteredBooks = filterBooksByYear(1950);
// console.log(filteredBooks);

filteredBooks.sort((a, b) => sortByYear(a, b));
// console.log(filteredBooks);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:141.0) Gecko/20100101 Firefox/141.0

Challenge Information:

Build a Book Organizer - Build a Book Organizer

you do not need to write this arrow function, you need to use the function you have directly

With this Lab I could start to fill the gap where I did not fully understand.

It also leads me to read more about Array.prototype.sort() on MDN.

code removed by moderator

1 Like

Thanks. Before you reply I follow instructions from previous reply to resolve the error.

hi @hatswd

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Even I had gotten the correct answer, I still have some doubts, for the sort function no parameter input is required? I just not fully understand.

sort requires a function, you can create the function in place as an argument, or you can use an existing function, in this case you already have an existing function available to use and should use it

Thanks for your replies. But for the sortByYear function, also no input was given to it. I just started to learn JS, don’t have too much knowledge, I don’t know how it works between sort function and the function it callbacks.

the sort method will call the function and pass the elements to it

same way it would give the input to the arrow function you wrote .sort((a,b) => …) the two parameters a and b will get a value when sort calls the function