Build a Book Organizer - Build a Book Organizer

Tell us what’s happening:

Test 11 isn’t passing for me, could anyone help point me in the right direction?

Your code so far

let books = [
  {
    title: "Watchmen",
    authorName: "Alan Moore",
    releaseYear: 1986,
  },
   {
    title: "V for Vendetta",
    authorName: "Alan Moore",
    releaseYear: 1940,
  },
   {
    title: "Jerusalem",
    authorName: "Alan Moore",
    releaseYear: 2016,
  },
]

 
function sortByYear(book1, book2){
  if (book1.releaseYear - book2.releaseYear > 0){
    return 1
  }
  if (book1.releaseYear - book2.releaseYear == 0){
    return 0
  }
  if (book1.releaseYear - book2.releaseYear < 0){
    return -1
  }

}

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

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


filteredBooks.sort(function(sortByYear) {
  console.log((a, b) => a - b);
});

console.log(filteredBooks);




Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36

Challenge Information:

Build a Book Organizer - Build a Book Organizer

here you are passing this function function(sortByYear) { console.log((a, b) => a - b); } and it has a sortByYear parameter, you are not passing the function sortByYear as callback

is there something you can point me to to read? I am a little lost on what specifically I need to do

consider that you passed a function to sort, but you passed a wrong one, instead which is the function you are asked to pass? sortByYear, it already exists as sortByYear so you don’t need to create a new function, you just pass it

related lesson:
How Does the Sort Method Work?

I just do not understand this lol

have you seen the first example in the lesson?

array.sort(compareFunction);

have you tried applying this?
you have your compareFunction, it’s called sortByYear

They keyword function defines a function. You only need to do that once.

Once it’s defined call it by just writing it’s name and brackets (and any arguments)

function hello() {
    console.log("hello")
}

hello()

If you want to pass that function to another function don’t define it again. You need to pass a function reference to sort so you can omit the brackets. (You are passing the function name, not actually calling the function at that time)

something.sort(hello)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort

i figured it out finally, I was way overthinking it.

1 Like