Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { libraryShelf } from '../common/library-shelf.js';
- export class Library {
- #shelves = {
- 1: [],
- 2: [],
- 3: [],
- 4: [],
- 99: [],
- };
- set _shelves(obj) {
- for (const keys in obj) {
- const shelf = keys;
- const book = obj[keys][0];
- this.addBook(book, shelf);
- }
- }
- get _shelves() {
- return this.#shelves;
- }
- addBook(book, shelf) {
- if (!libraryShelf[shelf]) {
- throw new Error('Not a valid shelf.');
- }
- this.#shelves[shelf].push(book);
- }
- get _shelves() {
- return this.#shelves;
- }
- printBooks() {
- let outPut = '';
- // eslint-disable-next-line guard-for-in, prefer-const
- for ( let keys in this.#shelves) {
- if (this.#shelves[keys].length !== 0) {
- outPut += ('==' + libraryShelf[keys] + '==' +'\n');
- this.#shelves[keys].map(el =>{
- outPut += el.title + ', by ' + el.authors + ', ' + el.pages + ' pages' + '\n';
- });
- }
- }
- if (outPut === '') {
- return 'No books added';
- } else {
- return outPut;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment