Build a Book Organizer - Steps 8 & 9

Hello campers. I have spent severals hours trying to find what I made wrong. But I can’t do it. Please somebody help me because the result i got is correct but can’t pass the automation script that validates my code.

Here is my code:

const books = [
  {
  title: "Clean Code",
  authorName: "Robert C. Martin",
  releaseYear: 2008
},
{
  title: "You Dont Know JS: Scope & Closures",
  authorName: "Kyle Simpson",
  releaseYear: 2014
},
{
  title: "JavaScript: The Good Parts",
  authorName: "Douglas Crockford",
  releaseYear: 2007
}
];

function sortByYear(b1, b2) {
    if (b1.releaseYear < b2.releaseYear)
      return -1;
    else if (b1.releaseYear > b2.releaseYear)
      return 1;
    else return 0;
}

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

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

console.log(sortByYear(books[1], books[0]));
console.log(filteredBooks)

Hi. Can you please post the link to the challenge.

Yes, of course. Sorry I miss that!

Hi.

You have added a layer of code not asked for. You need to follow this exactly:

Test 9: " * You should call the sort higher order function by passing the sortByYear callback function on the filteredBooks array."

Test 8 - look at the order of your code.

Hi, thanks! That’s how it worked.

const books = [
  {
  title: "Clean Code",
  authorName: "Robert C. Martin",
  releaseYear: 2008
},
{
  title: "You Dont Know JS: Scope & Closures",
  authorName: "Kyle Simpson",
  releaseYear: 2014
},
{
  title: "JavaScript: The Good Parts",
  authorName: "Douglas Crockford",
  releaseYear: 2007
}
];

function sortByYear(b1, b2) {
    if (b1.releaseYear < b2.releaseYear)
      return -1;
    else if (b1.releaseYear > b2.releaseYear)
      return 1;
    else return 0;
}
[

console.log(sortByYear(books[1], books[0]));
console.log(filteredBooks)

[mod edit - solution removed]
For the step 8 I only changed the year for the filter.

Good to hear you resolved it.

I have removed the solution from your code as this is against the rules.

1 Like