Skip to content
Open

done #612

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 118 additions & 25 deletions src/books.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,86 @@


// 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)




// 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)








Expand All @@ -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))