Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* eslint-disable linebreak-style */
- import { libraryShelf } from '../common/library-shelf.js';
- export class Library {
- _shelves;
- constructor() {
- this._shelves = {};
- }
- addBook(book, shelf) {
- if (!Object.values(libraryShelf).includes(shelf)) {
- throw Error('The shelf value is invalid');
- }
- if (!(shelf in this._shelves)) {
- this._shelves[shelf] = [];
- }
- this._shelves[shelf].push(book);
- }
- printBooks() {
- const title = '---Task Board ---\nTasks:\n';
- if (Object.keys(this._shelves).length === 0) {
- console.log(title + 'No books added');
- } else {
- let shelfAsString = '';
- // eslint-disable-next-line guard-for-in
- for (const key in this._shelves) {
- const element = this._shelves[key];
- shelfAsString += ` == ${libraryShelf[key]} == \n`;
- element.forEach(el => {
- shelfAsString += `${el.title}, by ${el.authors}, ${el.pages} \n`;
- });
- // if (Object.hasOwn(this._shelves, key)) {
- // element.map(el => shelfAsString += console.log(el.toString()));
- // // shelfAsString += this._shelves[key].map(el => el.toString());
- // }
- }
- console.log(title + shelfAsString);
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment