Tell us what’s happening:
I don’t really get why my sortByYear fonction cannot pass the third test, and i don’t really get why if i replace all my fonctions with the one that i put in comments, it passes the test even though it doesn’t work at all and always returns 0.
Your code so far
let books = [{
title: "Issou",
authorName: "Risitas",
releaseYear: 2013,
},{
title: "La Chancla",
authorName: "Jesus",
releaseYear: 2011,
},{
title: "Cunao",
authorName: "Risitas",
releaseYear: 2009,
},];
function getBook(bookName){
let filter = books.filter(book => bookName === book.title);
return filter.map((book) => book.releaseYear);
}
const sortByYear = (book1, book2) => {
if (getBook(book1) > getBook(book2)){
return 1
} else if (getBook(book1) < getBook(book2)){
return -1;
} else {
return 0;
}
}
/* This fonction will pass the test even though it doesn't work :
const sortByYear = (book1, book2) => {
if (book1.releaseYear < book2.releaseYear) {
return -1;
} else if (book1.releaseYear > book2.releaseYear) {
return 1;
} else {
return 0;
};
};
*/
console.log(sortByYear("Issou", "Cunao"));
const filteredBooks = books.filter(book => book.releaseYear >= 2010)
filteredBooks.sort(sortByYear);
console.log(filteredBooks);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Challenge Information:
Build a Book Organizer - Build a Book Organizer