Build a Book Organizer - Build a Book Organizer

Tell us what’s happening:

I am having issues satisfying Test case 9. On line 39 I believe I am calling the sort higher-order function with sortByYear as the callback function, a console log of the modified filteredBooks array shows that the objects have infact been sorted into ascending order but I still cannot pass Test Case 9. Can somebody please inform me what I have done wrong and the correct way to satisfy this step, thank you

Your code so far

let books = [

{title:"Once Upon an Algorithm",authorName:"Martin Erwig",releaseYear:2017},

{title:"Zero to One",authorName:"Peter Thiel",releaseYear:2014},

{title:"The Chocolate Chip Cookie Book",authorName:"Katie Jacobs",releaseYear:2023},

{title:"The Linux Programming Interface",authorName:"Michael Kerrisk",releaseYear: 2010}

];

function sortByYear(book1,book2)
{

  let sortResult = book1.releaseYear - book2.releaseYear;

if(sortResult > 0)
{

  return 1;

}else if(sortResult == 0)
{

  return 0;

}else
{

  return -1;

}

}

const filteredBooks = books.filter((book) => book.releaseYear > 2010);

filteredBooks.sort((book1,book2)=>sortByYear(book1,book2));

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0

Challenge Information:

Build a Book Organizer - Build a Book Organizer

Double check the syntax of .sort() and what argument it takes.

Thank you, I see that I was doing too much in my solution, problem solved

1 Like

I have the same thing as your code, i didn’t understand what is missing. What was the issue? I saw the sort() syntax and not sure what i am missing, it is working as expected but is failing this test. @BGagoDevs

hi @praveenamir

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Get Help > Ask for Help button located on the challenge.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.