From 7dc871e0c53118ba426fa1d896b1996d9c723ad4 Mon Sep 17 00:00:00 2001 From: carliitosway-collab Date: Sat, 15 Nov 2025 19:38:50 +0100 Subject: [PATCH] done --- src/books.js | 143 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 118 insertions(+), 25 deletions(-) diff --git a/src/books.js b/src/books.js index c8119bb..fa9b588 100644 --- a/src/books.js +++ b/src/books.js @@ -38,21 +38,69 @@ // Your code here: -const booksArray = []; +const booksArray = [ + { + title: "The Old Man and the Sea", + pages: 128, + author: "Ernest Hemingway", + details: { + language: "English", + description: "One of Hemingway's most famous work, it tells the story of Santiago..." + } + }, + { + title: "The Airbnb Story", + pages: 256, + author: "Leight Gallagher", + details: { + language: "English", + description: "This is the remakable behind-the-scenes strory of the creation and growth of Airbnb..." + } + }, + { + title: "Educated - A Memoir", + pages: 352, + author: "Tara Westover", + details: { + language: "English", + description: "Educated is an account of the struggle for self-invention..." + } + }, + { + title: "The Art of Learnig", + pages: 288, + author: "Josh Waitzkin", + details: { + language: "English", + details: "The Art of Learning takes readers through Waitzkin's unique journey to excellence. He explains in clear detail how a well-thought-out, principled approach to learning is what separates success from failure. " + } + } +]; // Iteration 2 | Book Details -function getBookDetails() { - // Your code here: - +// Your code here: +function getBookDetails(book) { + return `${book.title} - ${book.author} - ${book.pages} pages`; } +const bookExample = { + title: "The Art of Learning", + author: "Josh Waitzkin", + pages: 288, +} +//console.log(getBookDetails(bookExample)) + // Iteration 3 | Delete Language // Your code here: +for (let i = 0; i < booksArray.length; i++) { + delete booksArray[i].details.language; +} +//console.log(booksArray) @@ -60,6 +108,16 @@ function getBookDetails() { // Iteration 4 | Estimated Reading Time // Your code here: +for (let i = 0; i < booksArray.length; i++) { + const minutes = (booksArray[i].pages * 500) / 90; + booksArray[i].readingTime = Math.ceil(minutes); +} +//console.log(booksArray) + + + + + @@ -69,32 +127,67 @@ function getBookDetails() { The book info is stored in arrays with structure: [title, pages]. */ const dictionary = { - "J. K. Rowling": [ - ["Harry Potter and the Philosopher's Stone", 223], - ["Harry Potter and the Chamber of Secrets", 251], - ["Harry Potter and the Prisoner of Azkaban", 317], - ["Harry Potter and the Goblet of Fire", 636], - ], - "Neal Stephenson": [ - ["Cryptonomicon", 928], - ["Anathem", 1008], - ["Fall; or, Dodge in Hell", 896], - ], - "Malcolm Gladwell": [ - ["Outliers", 320], - ["Blink", 287], - ], + "J. K. Rowling": [ + ["Harry Potter and the Philosopher's Stone", 223], + ["Harry Potter and the Chamber of Secrets", 251], + ["Harry Potter and the Prisoner of Azkaban", 317], + ["Harry Potter and the Goblet of Fire", 636], + ], + "Neal Stephenson": [ + ["Cryptonomicon", 928], + ["Anathem", 1008], + ["Fall; or, Dodge in Hell", 896], + ], + "Malcolm Gladwell": [ + ["Outliers", 320], + ["Blink", 287], + ], }; -function booksByAuthor() { - // Your code here: - +// Your code here: + + +function booksByAuthor(dictionary) { + const result = []; + + for (let author in dictionary) { + const booksArray = dictionary[author]; + + for (let i = 0; i < booksArray.length; i++) { + const book = booksArray[i]; + + result.push({ + title: book[0], + pages: book[1], + author: author + }); + } + } + + return result; } +console.log(booksByAuthor(dictionary)); // Bonus: Iteration 6 | Average Page Count -function averagePageCount() { - // Your code here: - + +// Your code here: +function averagePageCount(books) { + let totalPages = 0; + + for (let i = 0; i < books.length; i++) { + totalPages += books[i].pages; + } + + return totalPages / books.length; } + + +console.log(averagePageCount(booksArray)) + + + + + +