Skip to content
Open

done #684

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
132 changes: 110 additions & 22 deletions src/books.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
// Iteration 1 | Books Array
/*
In the index.js file, create an array named booksArray containing 4 objects representing the books described in the code snippet below. Each object should have the following properties:

title
pages
author
details

The values of the properties should be the same as the ones in the following code snippet:
*/

// Book 1
// title: The Old Man and the Sea
Expand Down Expand Up @@ -37,64 +47,142 @@
// }


// Your code here:
const booksArray = [];


// Your code here:
const booksArray = [
{
title: "The Old Man and the Sea",
pages: 128,
author: "Ernest Hemingway",
details: [
{ languages: "English" },
{ description: "One of Hemingway's most famous works, it tells the story of Santiago..." }
]
},
{
title: "The Airbnb Story",
pages: 256,
author: "Leight Gallagher",
details: [
{ languages: "English" },
{ description: "This is the remarkable behind-the-scenes story 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 Learning",
pages: 288,
author: "Josh Waitzkin",
details: [
{ language: "English" },
{ description: "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:
/*
Create a function named getBookDetails() that takes one argument - the book object. The function should return a string in the following format:

"TITLE - AUTHOR - PAGES pages"
*/

function getBookDetails(booksArray) {
// Your code here:
return booksArray.title + " - " + booksArray.author + " - " + booksArray.pages + " pages";
}



// Iteration 3 | Delete Language
/*
Iterate over the booksArray, and delete the nested object property language from each book object.
Once done, console.log the booksArray array to confirm that the property has been deleted from all the book objects.

Note: You shouldn't change the booksArray manually, but instead, you should iterate over the array and delete the property from each book object.
*/

// Your code here:

booksArray.forEach(function(book) {
delete book.language;
});
console.log(booksArray);



// Iteration 4 | Estimated Reading Time
// Your code here:
/*
Iterate over the booksArray, and add a new property readingTime to each book object.
The value of the readingTime should be the number of minutes it will take to read the book. The number of minutes should be an integer (i.e., no decimals).

Assuming a page consists of 500 words and that the average reader reads 90 words per minute, the estimated reading time for a book can be calculated using the following formula:

reading time in minutes = (number of pages * 500) / 90

The reading time must be rounded UP to the next whole number, even if the result is a small decimal. For example:

If the result is 711.1, round it up to 712.
If the result is 30.03, round it up to 31.
Once done, console.log the booksArray to confirm that the property has been added to each book object.

*/

// Your code here:
booksArray.forEach(function(book) {
book.readingTime = Math.ceil((book.pages * 500) / 90);
});
console.log(booksArray);



// Bonus: Iteration 5 | Books Dictionary
/*
For this iteration, in the books.js file we have provided you with an object named dictionaryExample.
The dictionaryExample object contains different books grouped by the author. Each book is represented by an array containing two elements - the book title and the number of pages:
*/


/* The `dictionary` is an object containing books grouped by author.
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:

}



// Bonus: Iteration 6 | Average Page Count
function averagePageCount() {
// Your code here:

}