mr_anastasov

booksByGenre

Apr 28th, 2023
716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import * as data from './book-data.js'
  2.  
  3.  
  4. const books = data.books;
  5. const genre = data.bookGenre;
  6.  
  7. const pagesInRange = (books).sort((a, b) => a.pages - b.pages);
  8.  
  9.  
  10. // I want to map the books to have genere name instead of id, after that I need to return only the books that return a specified genere.
  11. const booksByGenre = (books, findThisGenre) => {
  12.  
  13.     let bookArr = books.map((book) => {
  14.         for (const key in genre) {
  15.             console.log(genre[key] === book.genre)
  16.             if (genre[key] === book.genre) {
  17.                 console.log(book.genre, key)
  18.                 book.genre = key;
  19.                 console.log(book);
  20.             }
  21.         }
  22.     })
  23.     console.log(bookArr);
  24.  
  25.     return bookArr.some((el) => {
  26.         el.genre === findThisGenre;
  27.     })
  28.     };
  29.  
  30. const check = booksByGenre;
  31. console.log(check(books, 'Sci-Fi'));
Advertisement
Add Comment
Please, Sign In to add comment