text: const authors = require("./authors.json");
  const books = require("./books.json");
  
  /**************************************************************
   * getBookById(bookId, books):
   * - receives a bookId
   * - recieves an array of book objects
   * - returns the book object that matches that id
   * - returns undefined if no matching book is found
   ****************************************************************/
  const getBookById = (bookId, books) => books.find((book) => book.id === bookId);
  
  // console.log(getBookById(12, books));
  
  /**************************************************************
   * getAuthorByName(authorName, authors):
   * - receives an authorName
   * - recieves an array of author objects
   * - returns the author that matches that name (CASE INSENSITIVE)
   * - returns undefined if no matching author is found
   ****************************************************************/
  const getAuthorByName = (authorName, authors) =>
    authors.find((author) => author.name === authorName);
  
  // console.log(getAuthorByName("J.K. Rowling", authors));
  
  /**************************************************************
   * bookCountsByAuthor(authors):
   * - receives an array of authors
   * - returns an array of objects with the format:
   *    [{ author: <NAME>, bookCount: <NUMBER_OF_BOOKS> }]
   ****************************************************************/
  const bookCountsByAuthor = (authors) =>
    authors.flatMap((author) => [
      "{ author: " + author.name,
      " bookCount: " + author.books.length + " }",
    ]);
  
  // console.log(bookCountsByAuthor(authors));
  
  /**************************************************************
   * booksByColor(books):
   * - receives an array of books
   * - returns an object where the keys are colors
   *   and the values are arrays of book titles:
   *    { <COLOR>: [<BOOK_TITLES>] }
   ****************************************************************/
  function booksByColor(books) {
    const colors = {
      white: books
        .filter((book) => book.color === "white")
        .map((bookfiltered) => bookfiltered.title),
      yellow: books
        .filter((book) => book.color === "yellow")
        .map((bookfiltered) => bookfiltered.title),
      red: books
        .filter((book) => book.color === "red")
        .map((bookfiltered) => bookfiltered.title),
      blue: books
        .filter((book) => book.color === "blue")
        .map((bookfiltered) => bookfiltered.title),
      green: books
        .filter((book) => book.color === "green")
        .map((bookfiltered) => bookfiltered.title),
      purple: books
        .filter((book) => book.color === "purple")
        .map((bookfiltered) => bookfiltered.title),
      black: books
        .filter((book) => book.color === "black")
        .flatMap((bookfiltered) => bookfiltered.title),
      grey: books
        .filter((book) => book.color === "grey")
        .map((bookfiltered) => bookfiltered.title),
      orange: books
        .filter((book) => book.color === "orange")
        .flatMap((bookfiltered) => bookfiltered.title),
    };
  
    return colors;
  }
  // console.log(booksByColor(books));
  
  /**************************************************************
   * titlesByAuthorName(authorName, authors, books):
   * - receives an authorName
   * - recieves an array of author objects
   * - recieves an array of book objects
   * - returns an array of the titles of the books written by that author:
   *    ["The Hitchhikers Guide", "The Meaning of Liff"]
   ****************************************************************/
  function titlesByAuthorName(authorName, authors, books) {
    let x = authors
      .filter((author) => author.name === authorName)
      .flatMap((authornamefiltered) => authornamefiltered.books);
    // console.log(x);
  }
  
  // console.log(titlesByAuthorName("George R.R. Martin", authors, books));
  
  /**************************************************************
   * mostProlificAuthor(authors):
   * - receives a list of authors
   * - returns the name of the author with the most books
   *
   * Note: assume there will never be a tie
   ****************************************************************/
  function mostProlificAuthor(authors) {
    let arr = [authors.flatMap((author) => parseInt(author.books.length))];
    let max = Math.max(arr);
    console.log(max);
  }
  console.log(mostProlificAuthor(authors));
  
  /**************************************************************
   * relatedBooks(bookId, authors, books):
   * - receives a bookId
   * - receives a list of authors
   * - receives a list of books
   * - returns a list of the titles of all the books by
   *   the same author as the book with bookId
   *   (including the original book)
   *
   * e.g. Let's send in bookId 37 ("The Shining Girls" by Lauren Beukes):
   *      relatedBooks(37);
   * We should get back all of Lauren Beukes's books:
   *      ["The Shining Girls", "Zoo City"]
   *
   * NOTE: YOU NEED TO TAKE INTO ACCOUNT BOOKS WITH MULTIPLE AUTHORS
   *
   * e.g. Let's send in bookId 46 ("Good Omens" by Terry Pratchett and Neil Gaiman):
   *      relatedBooks(46);
   * We should get back all of Neil Gaiman's books AND all of Terry Pratchett's books:
   *      ["Good Omens", "Good Omens", "Neverwhere", "Coraline", "The Color of Magic", "The Hogfather", "Wee Free Men", "The Long Earth", "The Long War", "The Long Mars"]
   *
   * BONUS: REMOVE DUPLICATE BOOKS
   ****************************************************************/
  function relatedBooks(bookId, authors, books) {
    // Your code goes here
  }
  // console.log(relatedBooks(50, authors, books));
  
  /**************************************************************
   * friendliestAuthor(authors):
   * - receives a list of authors
   * - returns the name of the author that has
   *   co-authored the greatest number of books
   ****************************************************************/
  function friendliestAuthor(authors) {
    // Your code goes here
  }
  // console.log(friendliestAuthor(authors));
  
  module.exports = {
    getBookById,
    getAuthorByName,
    bookCountsByAuthor,
    booksByColor,
    titlesByAuthorName,
    mostProlificAuthor,
    relatedBooks,
    friendliestAuthor,
  };
  
  /**
   * Uncomment the following lines if you
   * want to manually test your code
   */
  