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