My project wants me to use a function called filterBooks
. Tis function’s purpose is to Filter books based on search input. It wants me to use a function from a helper.js
called flattenObjectValuesIntoArray
. This function loops throught the books object which is in a booklist.js
and it flatten object keys into an array so that we search the entire object by the input value.
This is the exact instruction :
The filterBooks() function takes in a search string and a list of books as parameters and returns all of the books that contain an exact match of the search input as an array of objects. Objects in this array should be formatted as books with title, author, and tags properties, similar to the original books array. It should use the flattenObjectValuesIntoArray() function to search all fields within a book object easily.
const filterBooks = (books, barInput) => {
return books.filter((book) => {
const values = flattenObjectValuesIntoArray([book]); // Flatten book into values
return values.some((value) =>
value.toString().toLowerCase().includes(barInput.toLowerCase())
);
});
};
What I expected was when I typed a value from the Books object, the filterBooks
function would return the books that had that word or value. but when I searched a word in the search bar nothing happened .