function relatedBooks(bookId, authors, books) {
  // Your code goes here
  let titleList = [];
  let bookAuthor = getBookById(bookId, books).authors;
  bookAuthor.forEach((authorObj) =>
    titleList.push(titlesByAuthorName(authorObj.name, authors, books))
  );
  let finalArray = [];
  titleList.forEach((elem) => finalArray.push(...elem));
  return finalArray.sort();
  // finalArray = [...new Set(finalArray)];
  // without duplicates
  // return finalArray;
}
/**************************************************************
 * 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
 ****************************************************************/
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)



YOU NEED TO TAKE INTO ACCOUNT BOOKS WITH MULTIPLE AUTHORS



REMOVE DUPLICATE BOOKS
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 ) YOU NEED TO TAKE INTO ACCOUNT BOOKS WITH MULTIPLE AUTHORS REMOVE DUPLICATE BOOKS
function relatedBooks(bookId, authors, books) {
  let titleList = [];
  let bookAuthor = getBookById(bookId, books).authors;
  bookAuthor.forEach((authorObj) =>
    titleList.push(titlesByAuthorName(authorObj.name, authors, books))
  );
  let finalArray = [];
  titleList.forEach((elem) => finalArray.push(...elem));
  return finalArray.sort();
}
function relatedBooks ( bookId , authors , books ) { let titleList = [ ] ; let bookAuthor = getBookById ( bookId , books ) . authors ; bookAuthor . forEach ( ( authorObj ) => titleList . push ( titlesByAuthorName ( authorObj . name , authors , books ) ) ) ; let finalArray = [ ] ; titleList . forEach ( ( elem ) => finalArray . push ( ... elem ) ) ; return finalArray . sort ( ) ; }
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)
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 )
// Your code goes here // finalArray = [...new Set(finalArray)]; // without duplicates // return finalArray;