Skip to content

Instantly share code, notes, and snippets.

@fasidOnGit
Created September 27, 2019 13:19
Show Gist options
  • Save fasidOnGit/134df98a4cc1068f2c908bd889312185 to your computer and use it in GitHub Desktop.
Save fasidOnGit/134df98a4cc1068f2c908bd889312185 to your computer and use it in GitHub Desktop.
class BookWithReviews {
constructor(id, title) {
this.id = id;
this.title = title;
this.reviews = [];
}
addReview(author, content) {
this.reviews.push({ author, content });
};
}
/**
* Parses passed books and reviews arrays to create an array of BookWithReviews object. Each row from books input array
* should have a corresponding row in resulting array. For example, for following input data:
* books = [ { "id" : 101, "title" : "Some book title" } ]
* reviews = [ { "bookId" : 101, "author" : "John", "content" : "Great book!" } ];
* It should return following result:
* result = [ { id: 101, title: "Some book title", reviews : [ { author: "John", content: "Great book!" }] } ];
*
* @param books - an array of input books, see 'src/app/dataset/books.json' for sample data.
* @param reviews - an array of input reviews, see 'src/app/dataset/reviews.json' for sample data.
* @returns {Array} - an array of BookWithReviews objects
*/
export function parseBooksData(books, reviews) {
//TODO: Implement
}
/**
* Displays data from passed `books` array. For example, if books argument would have following value:
* books = [ { id: 101, title: "Some book title", reviews : [ { author: "John", content: "Great book!" }] } ];
* then, following structure should be created under the parentNode:
* <ol>
* <li>
* <span>Some book title</span>
* <ul>
* <li>Great book! by John</li>
* </ul>
* </li>
* </ol>
* @param parentNode - parent node for all books
* @param books - an array of BookWithReviews objects.
*/
export function displayBooks(parentNode, books) {
// TODO: Implement
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment