refactor(curriculum): update higher order function workshop to break down steps further (#60435)

Co-authored-by: Kolade Chris <65571316+Ksound22@users.noreply.github.com>
This commit is contained in:
Jessica Wilkins 2025-07-02 08:08:57 -07:00 committed by GitHub
parent e2ec2c14b4
commit 4f0cd7aee3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 1459 additions and 376 deletions

View File

@ -20,24 +20,64 @@
"title": "Step 3"
},
{
"id": "67116d7584d0b469b14579c1",
"id": "681dbe48ee5df6842385d735",
"title": "Step 4"
},
{
"id": "67116d7584d0b469b14579c2",
"id": "681dc1bbbf0d2e85ac499cf6",
"title": "Step 5"
},
{
"id": "67116d7584d0b469b14579c3",
"id": "681dc623b2b18887266777b1",
"title": "Step 6"
},
{
"id": "67116d7584d0b469b14579c4",
"id": "6822576638d15cff700f091d",
"title": "Step 7"
},
{
"id": "67190ce4fe18911edc2018d2",
"id": "6822595203b35c00b87c0524",
"title": "Step 8"
},
{
"id": "68225ea2f1aae301fa4df0f4",
"title": "Step 9"
},
{
"id": "682264d807fe00058c1ea013",
"title": "Step 10"
},
{
"id": "67116d7584d0b469b14579c2",
"title": "Step 11"
},
{
"id": "6822694e3d34c807feeaba50",
"title": "Step 12"
},
{
"id": "68226c92f138dd09cd5b9722",
"title": "Step 13"
},
{
"id": "67116d7584d0b469b14579c3",
"title": "Step 14"
},
{
"id": "682277e2d3a05f0c5cf34d19",
"title": "Step 15"
},
{
"id": "6827deed7fc01f074c90fc0d",
"title": "Step 16"
},
{
"id": "6827e10547fdd308bca1c73d",
"title": "Step 17"
},
{
"id": "67116d7584d0b469b14579c4",
"title": "Step 18"
}
],
"helpCategory": "JavaScript",

View File

@ -1,40 +1,36 @@
---
id: 67116d7584d0b469b14579c2
title: Step 5
title: Step 11
challengeType: 1
dashedName: step-5
dashedName: step-11
---
# --description--
To display the book summaries, you can use the `about` property of each book.
To get a list of book summaries, you can use the `about` property of each book.
Create a `getBookSummaries` function with a single parameter, accepting an array with book objects. The `getBookSummaries` function should return an array containing all the `about` property value of each book.
Create a `getBookSummaries` function with a single parameter, accepting an array with book objects. You can name the parameter whatever you like.
The `getBookSummaries` function should return an array of strings representing the summary for each book.
# --hints--
You should create a `getBookSummaries` function.
```js
assert.isFunction(getBookSummaries)
assert.isFunction(getBookSummaries);
```
Your `getBookSummaries` function should have one parameter.
```js
assert.lengthOf(getBookSummaries, 1)
assert.lengthOf(getBookSummaries, 1);
```
Your `getBookSummaries` function should return an array.
```js
assert.isArray(getBookSummaries(library))
```
Your `getBookSummaries` function should use a higher order function. Ex. (`filter`, `map`, `reduce`).
```js
assert.match(getBookSummaries.toString(), /filter|map|reduce|forEach/);
assert.isArray(getBookSummaries(library));
```
Your `getBookSummaries` function should return an array with the same length as the array passed to it.
@ -150,16 +146,16 @@ const library = [
},
];
function displayBooks(catalog) {
let output = 'Books in the Library:\n';
console.log("Books in the Library:\n");
catalog.forEach((book) => {
output += `- ${book.title} by ${book.author} (${book.pages} pages)\n`;
});
return output;
function getBookInformation(catalog) {
return catalog.map(book => `${book.title} by ${book.author}`).join("\n");
}
console.log(getBookInformation(library));
console.log("\nList of book summaries:\n");
--fcc-editable-region--
--fcc-editable-region--

View File

@ -1,13 +1,34 @@
---
id: 67116d7584d0b469b14579c3
title: Step 6
title: Step 14
challengeType: 1
dashedName: step-6
dashedName: step-14
---
# --description--
Another useful thing to do is to get the books by their author.
In earlier lectures, you learned how to work with the `filter()` method which is used to return a new array of filtered results.
Here is an example:
```js
const developers = [
{ name: "Alice", city: "New York", age: 30 },
{ name: "Bob", city: "San Francisco", age: 25 },
{ name: "Charlie", city: "New York", age: 35 },
{ name: "Diana", city: "Chicago", age: 28 }
];
const newYorkCityDevelopers = developers.filter(dev => dev.city === "New York");
console.log(newYorkCityDevelopers);
/*
[
{ name: "Alice", city: "New York", age: 30 },
{ name: "Charlie", city: "New York", age: 35 }
]
*/
```
Create a `getBooksByAuthor` function with two parameters - an array with book objects and a string with the author.
@ -18,13 +39,13 @@ The function must return an array that contains the books by a particular author
You should create a `getBooksByAuthor` function.
```js
assert.isFunction(getBooksByAuthor)
assert.isFunction(getBooksByAuthor);
```
Your `getBooksByAuthor` function should have two parameters.
```js
assert.lengthOf(getBooksByAuthor, 2)
assert.lengthOf(getBooksByAuthor, 2);
```
Your `getBooksByAuthor` function should return an array.
@ -33,12 +54,6 @@ Your `getBooksByAuthor` function should return an array.
assert.isArray(getBooksByAuthor(library, ''));
```
Your `getBooksByAuthor` function should use a higher order function. Ex. (`filter`, `map`, `reduce`).
```js
assert.match(getBooksByAuthor.toString(), /filter|map|reduce|forEach/);
```
Your `getBooksByAuthor` function should return the correct number of books for any of the authors.
```js
@ -139,20 +154,24 @@ const library = [
},
];
function displayBooks(catalog) {
let output = 'Books in the Library:\n';
console.log("Books in the Library:\n");
catalog.forEach((book) => {
output += `- ${book.title} by ${book.author} (${book.pages} pages)\n`;
});
return output;
function getBookInformation(catalog) {
return catalog.map(book => `${book.title} by ${book.author}`).join("\n");
}
console.log(getBookInformation(library));
console.log("\nList of book summaries:\n");
function getBookSummaries(catalog) {
return catalog.map((book) => book.about);
return catalog.map((book) => book.about).join("\n");
}
console.log(getBookSummaries(library));
console.log("\nList of books by Arvid Kahl:\n");
--fcc-editable-region--
--fcc-editable-region--

View File

@ -1,33 +1,49 @@
---
id: 67116d7584d0b469b14579c4
title: Step 7
title: Step 18
challengeType: 1
dashedName: step-7
dashedName: step-18
---
# --description--
Finally, create a `getTotalPages` function with a single parameter, accepting an array with book objects. The function should return the total number of pages in the books from the array passed to the function.
For the last step of the workshop, you will review how to work with the `reduce()` method. This method is used to process an array and condense it into a single value.
Here is an example:
```js
const numbers = [1, 2, 3, 4, 5];
const sum = numbers.reduce((acc, curr) => acc + curr, 0);
console.log(sum); // 15
```
In the following example, the reducer function takes `acc` (which starts at 0, as specified by the second argument to `reduce`) and adds each number to it. This will return a sum of `15`.
Create a `getTotalPages` function with a single parameter, accepting an array with book objects. The function should return the total number of pages in the books from the array passed to the function.
Lastly, add a `console.log(getTotalPages(library))` below your `getTotalPages` function to see the result.
With that, your library manager workshop is complete!
# --hints--
You should create a `getTotalPages` function.
```js
assert.isFunction(getTotalPages)
assert.isFunction(getTotalPages);
```
Your `getTotalPages` function should have one parameter.
```js
assert.lengthOf(getTotalPages, 1)
assert.lengthOf(getTotalPages, 1);
```
Your `getTotalPages` function should return a number.
```js
assert.isNumber(getTotalPages(library))
assert.isNumber(getTotalPages(library));
```
Your `getTotalPages` function should return the total number of pages in the books from the array passed to it.
@ -58,10 +74,10 @@ const _differentLibrary = [
assert.strictEqual(getTotalPages(_differentLibrary), 944);
```
Your `getTotalPages` function should use a higher order function. Ex. (`filter`, `map`, `reduce`).
You should have a `console.log(getTotalPages(library))`.
```js
assert.match(getTotalPages.toString(), /filter|map|reduce|forEach/);
assert.match(code, /console\.log\(\s*getTotalPages\(\s*library\)\s*\);?/);
```
# --seed--
@ -121,26 +137,127 @@ const library = [
},
];
function displayBooks(catalog) {
let output = 'Books in the Library:\n';
console.log("Books in the Library:\n");
catalog.forEach((book) => {
output += `- ${book.title} by ${book.author} (${book.pages} pages)\n`;
});
return output;
function getBookInformation(catalog) {
return catalog.map(book => `${book.title} by ${book.author}`).join("\n");
}
console.log(getBookInformation(library));
console.log("\nList of book summaries:\n");
function getBookSummaries(catalog) {
return catalog.map((book) => book.about);
return catalog.map((book) => book.about).join("\n");
}
console.log(getBookSummaries(library));
console.log("\nList of books by Arvid Kahl:\n");
function getBooksByAuthor(catalog, author) {
return catalog.filter((book) => book.author === author);
}
console.log(getBooksByAuthor(library, "Arvid Kahl"));
console.log("\nList of books by James Clear:\n");
console.log(getBooksByAuthor(library, "James Clear"));
console.log("\nTotal number of pages for all library books:\n");
--fcc-editable-region--
--fcc-editable-region--
```
# --solutions--
```js
const library = [
{
title: 'Your Next Five Moves: Master the Art of Business Strategy',
author: 'Patrick Bet-David and Greg Dinkin',
about: 'A book on how to plan ahead',
pages: 320,
},
{
title: 'Atomic Habits',
author: 'James Clear',
about: 'A practical book about discarding bad habits and building good ones',
pages: 320,
},
{
title: 'Choose Your Enemies Wisely: Business Planning for the Audacious Few',
author: 'Patrick Bet-David',
about:
"A book that emphasizes the importance of identifying and understanding one's adversaries to succeed in the business world",
pages: 304,
},
{
title: 'The Embedded Entrepreneur',
author: 'Arvid Kahl',
about: 'A book focusing on how to build an audience-driven business',
pages: 308,
},
{
title: 'How to Be a Coffee Bean: 111 Life-Changing Ways to Create Positive Change',
author: 'Jon Gordon',
about: 'A book about effective ways to lead a coffee bean lifestyle',
pages: 256,
},
{
title: 'The Creative Mindset: Mastering the Six Skills That Empower Innovation',
author: 'Jeff DeGraff and Staney DeGraff',
about: 'A book on how to develop creativity and innovation skills',
pages: 168,
},
{
title: 'Rich Dad Poor Dad',
author: 'Robert Kiyosaki and Sharon Lechter',
about: 'A book about financial literacy, financial independence, and building wealth. ',
pages: 336,
},
{
title: 'Zero to Sold',
author: 'Arvid Kahl',
about: 'A book on how to bootstrap a business',
pages: 500,
},
];
console.log("Books in the Library:\n");
function getBookInformation(catalog) {
return catalog.map(book => `${book.title} by ${book.author}`).join("\n");
}
console.log(getBookInformation(library));
console.log("\nList of book summaries:\n");
function getBookSummaries(catalog) {
return catalog.map((book) => book.about).join("\n");
}
console.log(getBookSummaries(library));
console.log("\nList of books by Arvid Kahl:\n");
function getBooksByAuthor(catalog, author) {
return catalog.filter((book) => book.author === author);
}
console.log(getBooksByAuthor(library, "Arvid Kahl"));
console.log("\nList of books by James Clear:\n");
console.log(getBooksByAuthor(library, "James Clear"));
console.log("\nTotal number of pages for all library books:\n");
function getTotalPages(catalog) {
return catalog.reduce((acc, book) => acc + book.pages, 0);
}
console.log(getTotalPages(library));
```

View File

@ -1,264 +0,0 @@
---
id: 67190ce4fe18911edc2018d2
title: Step 8
challengeType: 1
dashedName: step-8
---
# --description--
Now, you should test out the functions by calling them with the appropriate arguments.
Create four new variables: `libraryBooks`, `bookSummaries`, `booksByArvidKahl`, and `totalPagesOfBooksInLibrary`. Set them all to the calling of `displayBooks()`, `getBookSummaries()`, `getBooksByAuthor()`, and `getTotalPages()` respectively with the appropriate parameters.
Log all the variables to the console.
With that, your library manager workshop is complete.
# --hints--
You should create a `libraryBooks` variable.
```js
assert.isNotNull(libraryBooks)
```
Your `libraryBooks` variable should be set to `displayBooks(library)`.
```js
assert.equal(libraryBooks, displayBooks(library));
```
You should log the `libraryBooks` variable to the console.
```js
assert.match(code, /console\.log\(libraryBooks\);?/)
```
You should create a `bookSummaries` variable.
```js
assert.isNotNull(bookSummaries)
```
Your `bookSummaries` variable should be set to `getBookSummaries(library)`.
```js
assert.deepEqual(bookSummaries, getBookSummaries(library));
```
You should log the `bookSummaries` variable to the console.
```js
assert.match(code, /console\.log\(bookSummaries\);?/)
```
You should create a `booksByArvidKahl` variable.
```js
assert.isNotNull(booksByArvidKahl)
```
Your `booksByArvidKahl` variable should be set to `getBooksByAuthor(library, 'Arvid Kahl')`.
```js
assert.deepEqual(booksByArvidKahl, getBooksByAuthor(library, 'Arvid Kahl'));
```
You should log the `booksByArvidKahl` variable to the console.
```js
assert.match(code, /console\.log\(booksByArvidKahl\);?/)
```
You should create a `totalPagesOfBooksInLibrary` variable.
```js
assert.isNotNull(totalPagesOfBooksInLibrary)
```
Your `totalPagesOfBooksInLibrary` variable should be set to `getTotalPages(library)`.
```js
assert.deepEqual(totalPagesOfBooksInLibrary, getTotalPages(library));
```
You should log the `totalPagesOfBooksInLibrary` variable to the console.
```js
assert.match(code, /console\.log\(totalPagesOfBooksInLibrary\);?/)
```
# --seed--
## --seed-contents--
```js
const library = [
{
title: 'Your Next Five Moves: Master the Art of Business Strategy',
author: 'Patrick Bet-David and Greg Dinkin',
about: 'A book on how to plan ahead',
pages: 320,
},
{
title: 'Atomic Habits',
author: 'James Clear',
about: 'A practical book about discarding bad habits and building good ones',
pages: 320,
},
{
title: 'Choose Your Enemies Wisely: Business Planning for the Audacious Few',
author: 'Patrick Bet-David',
about:
"A book that emphasizes the importance of identifying and understanding one's adversaries to succeed in the business world",
pages: 304,
},
{
title: 'The Embedded Entrepreneur',
author: 'Arvid Kahl',
about: 'A book focusing on how to build an audience-driven business',
pages: 308,
},
{
title: 'How to Be a Coffee Bean: 111 Life-Changing Ways to Create Positive Change',
author: 'Jon Gordon',
about: 'A book about effective ways to lead a coffee bean lifestyle',
pages: 256,
},
{
title: 'The Creative Mindset: Mastering the Six Skills That Empower Innovation',
author: 'Jeff DeGraff and Staney DeGraff',
about: 'A book on how to develop creativity and innovation skills',
pages: 168,
},
{
title: 'Rich Dad Poor Dad',
author: 'Robert Kiyosaki and Sharon Lechter',
about: 'A book about financial literacy, financial independence, and building wealth. ',
pages: 336,
},
{
title: 'Zero to Sold',
author: 'Arvid Kahl',
about: 'A book on how to bootstrap a business',
pages: 500,
},
];
function displayBooks(catalog) {
let output = 'Books in the Library:\n';
catalog.forEach((book) => {
output += `- ${book.title} by ${book.author} (${book.pages} pages)\n`;
});
return output;
}
function getBookSummaries(catalog) {
return catalog.map((book) => book.about);
}
function getBooksByAuthor(catalog, author) {
return catalog.filter((book) => book.author === author);
}
function getTotalPages(catalog) {
return catalog.reduce((acc, book) => acc + book.pages, 0);
}
--fcc-editable-region--
--fcc-editable-region--
```
# --solutions--
```js
const library = [
{
title: 'Your Next Five Moves: Master the Art of Business Strategy',
author: 'Patrick Bet-David and Greg Dinkin',
about: 'A book on how to plan ahead',
pages: 320,
},
{
title: 'Atomic Habits',
author: 'James Clear',
about: 'A practical book about discarding bad habits and building good ones',
pages: 320,
},
{
title: 'Choose Your Enemies Wisely: Business Planning for the Audacious Few',
author: 'Patrick Bet-David',
about:
"A book that emphasizes the importance of identifying and understanding one's adversaries to succeed in the business world",
pages: 304,
},
{
title: 'The Embedded Entrepreneur',
author: 'Arvid Kahl',
about: 'A book focusing on how to build an audience-driven business',
pages: 308,
},
{
title: 'How to Be a Coffee Bean: 111 Life-Changing Ways to Create Positive Change',
author: 'Jon Gordon',
about: 'A book about effective ways to lead a coffee bean lifestyle',
pages: 256,
},
{
title: 'The Creative Mindset: Mastering the Six Skills That Empower Innovation',
author: 'Jeff DeGraff and Staney DeGraff',
about: 'A book on how to develop creativity and innovation skills',
pages: 168,
},
{
title: 'Rich Dad Poor Dad',
author: 'Robert Kiyosaki and Sharon Lechter',
about: 'A book about financial literacy, financial independence, and building wealth. ',
pages: 336,
},
{
title: 'Zero to Sold',
author: 'Arvid Kahl',
about: 'A book on how to bootstrap a business',
pages: 500,
},
];
function displayBooks(catalog) {
let output = 'Books in the Library:\n';
catalog.forEach((book) => {
output += `- ${book.title} by ${book.author} (${book.pages} pages)\n`;
});
return output;
}
function getBookSummaries(catalog) {
return catalog.map((book) => book.about);
}
function getBooksByAuthor(catalog, author) {
return catalog.filter((book) => book.author === author);
}
function getTotalPages(catalog) {
return catalog.reduce((acc, book) => acc + book.pages, 0);
}
const bookSummaries = getBookSummaries(library);
console.log(bookSummaries);
const libraryBooks = displayBooks(library);
console.log(libraryBooks);
const booksByArvidKahl = getBooksByAuthor(library, 'Arvid Kahl');
console.log(booksByArvidKahl);
const totalPagesOfBooksInLibrary = getTotalPages(library);
console.log(totalPagesOfBooksInLibrary);
```

View File

@ -0,0 +1,84 @@
---
id: 681dbe48ee5df6842385d735
title: Step 4
challengeType: 1
dashedName: step-4
---
# --description--
The rest of the objects representing the books have been filled in for you.
Now would be a good time to start working on displaying the book information in the console. Over the next few steps, you will learn how to work with the `map()` method to achieve this goal.
Begin by logging the message `"Books in the Library:\n"` to the console. The newline character is added here because there should be a space between this message and the list of books.
# --hints--
You should log the message `"Books in the Library:\n"` to the console.
```js
assert.match(code, /console\.log\(("|')Books\s+in\s+the\s+Library:\\n\1\);?/);
```
# --seed--
## --seed-contents--
```js
const library = [
{
title: 'Your Next Five Moves: Master the Art of Business Strategy',
author: 'Patrick Bet-David and Greg Dinkin',
about: 'A book on how to plan ahead',
pages: 320,
},
{
title: 'Atomic Habits',
author: 'James Clear',
about: 'A practical book about discarding bad habits and building good ones',
pages: 320,
},
{
title: 'Choose Your Enemies Wisely: Business Planning for the Audacious Few',
author: 'Patrick Bet-David',
about:
"A book that emphasizes the importance of identifying and understanding one's adversaries to succeed in the business world",
pages: 304,
},
{
title: 'The Embedded Entrepreneur',
author: 'Arvid Kahl',
about: 'A book focusing on how to build an audience-driven business',
pages: 308,
},
{
title: 'How to Be a Coffee Bean: 111 Life-Changing Ways to Create Positive Change',
author: 'Jon Gordon',
about: 'A book about effective ways to lead a coffee bean lifestyle',
pages: 256,
},
{
title: 'The Creative Mindset: Mastering the Six Skills That Empower Innovation',
author: 'Jeff DeGraff and Staney DeGraff',
about: 'A book on how to develop creativity and innovation skills',
pages: 168,
},
{
title: 'Rich Dad Poor Dad',
author: 'Robert Kiyosaki and Sharon Lechter',
about: 'A book about financial literacy, financial independence, and building wealth. ',
pages: 336,
},
{
title: 'Zero to Sold',
author: 'Arvid Kahl',
about: 'A book on how to bootstrap a business',
pages: 500,
},
];
--fcc-editable-region--
--fcc-editable-region--
```

View File

@ -0,0 +1,88 @@
---
id: 681dc1bbbf0d2e85ac499cf6
title: Step 5
challengeType: 1
dashedName: step-5
---
# --description--
Next, create a function called `getBookInformation` with one parameter. This parameter will represent the array of books when the function is called. You can name this parameter whatever you like.
# --hints--
You should create a `getBookInformation` function.
```js
assert.isFunction(getBookInformation);
```
Your `getBookInformation` function should have one parameter.
```js
assert.lengthOf(getBookInformation, 1)
```
# --seed--
## --seed-contents--
```js
const library = [
{
title: 'Your Next Five Moves: Master the Art of Business Strategy',
author: 'Patrick Bet-David and Greg Dinkin',
about: 'A book on how to plan ahead',
pages: 320,
},
{
title: 'Atomic Habits',
author: 'James Clear',
about: 'A practical book about discarding bad habits and building good ones',
pages: 320,
},
{
title: 'Choose Your Enemies Wisely: Business Planning for the Audacious Few',
author: 'Patrick Bet-David',
about:
"A book that emphasizes the importance of identifying and understanding one's adversaries to succeed in the business world",
pages: 304,
},
{
title: 'The Embedded Entrepreneur',
author: 'Arvid Kahl',
about: 'A book focusing on how to build an audience-driven business',
pages: 308,
},
{
title: 'How to Be a Coffee Bean: 111 Life-Changing Ways to Create Positive Change',
author: 'Jon Gordon',
about: 'A book about effective ways to lead a coffee bean lifestyle',
pages: 256,
},
{
title: 'The Creative Mindset: Mastering the Six Skills That Empower Innovation',
author: 'Jeff DeGraff and Staney DeGraff',
about: 'A book on how to develop creativity and innovation skills',
pages: 168,
},
{
title: 'Rich Dad Poor Dad',
author: 'Robert Kiyosaki and Sharon Lechter',
about: 'A book about financial literacy, financial independence, and building wealth. ',
pages: 336,
},
{
title: 'Zero to Sold',
author: 'Arvid Kahl',
about: 'A book on how to bootstrap a business',
pages: 500,
},
];
console.log("Books in the Library:\n");
--fcc-editable-region--
--fcc-editable-region--
```

View File

@ -0,0 +1,129 @@
---
id: 681dc623b2b18887266777b1
title: Step 6
challengeType: 1
dashedName: step-6
---
# --description--
In prior lectures, you learned about the `map()` method which creates a new array by applying a given function to each element of the original array.
Here is an example:
```js
const developers = [
{ name: "Alice", city: "New York", title: "Frontend Developer" },
{ name: "Bob", city: "San Francisco", title: "Backend Developer" }
];
console.log(developers.map(dev => dev.name));
// ["Alice", "Bob"]
```
`dev` in this example represents each object in the `developers` array. Then, dot notation is used to get the `name` from the object. Lastly, the result will be a new array of names.
Inside the `getBookInformation` function, use the `map()` method on the `catalog` parameter to return a new array of just book titles. Refer to the example if you need help.
# --hints--
Your `getBookInformation` function should return an array.
```js
assert.isArray(getBookInformation(library));
```
Your `getBookInformation` function should return an array of strings which represents the book titles.
```js
const testLibrary = [
{
title: "Title A",
author: "Author A",
about: "About A",
pages: 320,
},
{
title: "Title B",
author: "Author B",
about: "About B",
pages: 320,
},
{
title: "Title C",
author: "Author C",
about: "About C",
pages: 304,
},
];
const expected = ["Title A", "Title B", "Title C"];
assert.deepEqual(getBookInformation(testLibrary), expected);
```
# --seed--
## --seed-contents--
```js
const library = [
{
title: 'Your Next Five Moves: Master the Art of Business Strategy',
author: 'Patrick Bet-David and Greg Dinkin',
about: 'A book on how to plan ahead',
pages: 320,
},
{
title: 'Atomic Habits',
author: 'James Clear',
about: 'A practical book about discarding bad habits and building good ones',
pages: 320,
},
{
title: 'Choose Your Enemies Wisely: Business Planning for the Audacious Few',
author: 'Patrick Bet-David',
about:
"A book that emphasizes the importance of identifying and understanding one's adversaries to succeed in the business world",
pages: 304,
},
{
title: 'The Embedded Entrepreneur',
author: 'Arvid Kahl',
about: 'A book focusing on how to build an audience-driven business',
pages: 308,
},
{
title: 'How to Be a Coffee Bean: 111 Life-Changing Ways to Create Positive Change',
author: 'Jon Gordon',
about: 'A book about effective ways to lead a coffee bean lifestyle',
pages: 256,
},
{
title: 'The Creative Mindset: Mastering the Six Skills That Empower Innovation',
author: 'Jeff DeGraff and Staney DeGraff',
about: 'A book on how to develop creativity and innovation skills',
pages: 168,
},
{
title: 'Rich Dad Poor Dad',
author: 'Robert Kiyosaki and Sharon Lechter',
about: 'A book about financial literacy, financial independence, and building wealth. ',
pages: 336,
},
{
title: 'Zero to Sold',
author: 'Arvid Kahl',
about: 'A book on how to bootstrap a business',
pages: 500,
},
];
console.log("Books in the Library:\n");
--fcc-editable-region--
function getBookInformation(catalog) {
}
--fcc-editable-region--
```

View File

@ -0,0 +1,90 @@
---
id: 6822576638d15cff700f091d
title: Step 7
challengeType: 1
dashedName: step-7
---
# --description--
Now it is time to see what the result will look like in the console.
Below your `getBookInformation` function, add a `console.log()` and pass in a `getBookInformation()` function call with `library` for the argument.
When done correctly, you should see an array of book titles in the console.
# --hints--
You should have `console.log(getBookInformation(library));` in your code.
```js
assert.match(code, /console\.log\(\s*getBookInformation\(\s*library\s*\)\);?/gi);
```
# --seed--
## --seed-contents--
```js
const library = [
{
title: 'Your Next Five Moves: Master the Art of Business Strategy',
author: 'Patrick Bet-David and Greg Dinkin',
about: 'A book on how to plan ahead',
pages: 320,
},
{
title: 'Atomic Habits',
author: 'James Clear',
about: 'A practical book about discarding bad habits and building good ones',
pages: 320,
},
{
title: 'Choose Your Enemies Wisely: Business Planning for the Audacious Few',
author: 'Patrick Bet-David',
about:
"A book that emphasizes the importance of identifying and understanding one's adversaries to succeed in the business world",
pages: 304,
},
{
title: 'The Embedded Entrepreneur',
author: 'Arvid Kahl',
about: 'A book focusing on how to build an audience-driven business',
pages: 308,
},
{
title: 'How to Be a Coffee Bean: 111 Life-Changing Ways to Create Positive Change',
author: 'Jon Gordon',
about: 'A book about effective ways to lead a coffee bean lifestyle',
pages: 256,
},
{
title: 'The Creative Mindset: Mastering the Six Skills That Empower Innovation',
author: 'Jeff DeGraff and Staney DeGraff',
about: 'A book on how to develop creativity and innovation skills',
pages: 168,
},
{
title: 'Rich Dad Poor Dad',
author: 'Robert Kiyosaki and Sharon Lechter',
about: 'A book about financial literacy, financial independence, and building wealth. ',
pages: 336,
},
{
title: 'Zero to Sold',
author: 'Arvid Kahl',
about: 'A book on how to bootstrap a business',
pages: 500,
},
];
console.log("Books in the Library:\n");
function getBookInformation(catalog) {
return catalog.map(book => book.title);
}
--fcc-editable-region--
--fcc-editable-region--
```

View File

@ -0,0 +1,132 @@
---
id: 6822595203b35c00b87c0524
title: Step 8
challengeType: 1
dashedName: step-8
---
# --description--
The array of book titles is nice, but it would be nice to display the `title` and `author` for each book like this:
```js
[
"Your Next Five Moves: Master the Art of Business Strategy by Patrick Bet-David and Greg Dinkin",
"Atomic Habits by James Clear",
"Choose Your Enemies Wisely: Business Planning for the Audacious Few by Patrick Bet-David",
...
]
```
Update your use of the `map()` method to instead return an array of strings in this format: `TITLE by AUTHOR`.
You will need to use either template literals or string concatenation with the `+` operator to achieve this result.
# --hints--
Your `getBookInformation` function should return an array.
```js
assert.isArray(getBookInformation(library));
```
Your `getBookInformation` function should return an array of strings with the `title` and `author` for each book.
```js
const testLibrary = [
{
title: "Title A",
author: "Author A",
about: "About A",
pages: 320,
},
{
title: "Title B",
author: "Author B",
about: "About B",
pages: 320,
},
{
title: "Title C",
author: "Author C",
about: "About C",
pages: 304,
},
];
const expected = [
"Title A by Author A",
"Title B by Author B",
"Title C by Author C"
];
assert.deepEqual(getBookInformation(testLibrary), expected);
```
# --seed--
## --seed-contents--
```js
const library = [
{
title: 'Your Next Five Moves: Master the Art of Business Strategy',
author: 'Patrick Bet-David and Greg Dinkin',
about: 'A book on how to plan ahead',
pages: 320,
},
{
title: 'Atomic Habits',
author: 'James Clear',
about: 'A practical book about discarding bad habits and building good ones',
pages: 320,
},
{
title: 'Choose Your Enemies Wisely: Business Planning for the Audacious Few',
author: 'Patrick Bet-David',
about:
"A book that emphasizes the importance of identifying and understanding one's adversaries to succeed in the business world",
pages: 304,
},
{
title: 'The Embedded Entrepreneur',
author: 'Arvid Kahl',
about: 'A book focusing on how to build an audience-driven business',
pages: 308,
},
{
title: 'How to Be a Coffee Bean: 111 Life-Changing Ways to Create Positive Change',
author: 'Jon Gordon',
about: 'A book about effective ways to lead a coffee bean lifestyle',
pages: 256,
},
{
title: 'The Creative Mindset: Mastering the Six Skills That Empower Innovation',
author: 'Jeff DeGraff and Staney DeGraff',
about: 'A book on how to develop creativity and innovation skills',
pages: 168,
},
{
title: 'Rich Dad Poor Dad',
author: 'Robert Kiyosaki and Sharon Lechter',
about: 'A book about financial literacy, financial independence, and building wealth. ',
pages: 336,
},
{
title: 'Zero to Sold',
author: 'Arvid Kahl',
about: 'A book on how to bootstrap a business',
pages: 500,
},
];
console.log("Books in the Library:\n");
--fcc-editable-region--
function getBookInformation(catalog) {
return catalog.map(book => book.title);
}
--fcc-editable-region--
console.log(getBookInformation(library));
```

View File

@ -1,80 +1,69 @@
---
id: 67116d7584d0b469b14579c1
title: Step 4
id: 68225ea2f1aae301fa4df0f4
title: Step 9
challengeType: 1
dashedName: step-4
dashedName: step-9
---
# --description--
The rest of the objects representing the books have been filled in for you. You can take a look at them.
While the array of results is working, the final desired result should be a string listing all of the books with a title and author.
Now, you should start working on getting several common parts of the books.
This is where the `join()` method comes in. In earlier lectures, you learned that the `join()` method is used to return a new string of all of the array elements concatenated into a single string, with a specified separator between each element.
Start by displaying all the books. Create a `displayBooks` function with a parameter accepting an array with book objects. The function should return a string that contains the `title`, `author`, and `pages` of all the books in the array passed to function.
Here is a refresher:
```js
const developers = ["Naomi", "Tom", "Jessica"];
const teamList = developers.join("\n");
console.log(teamList);
// Naomi
// Tom
// Jessica
```
The separator in this case is the `\n` which represents the newline character.
Chain the `join()` method with a `\n` for the separator to the `map()`. Now you should see a string in the console instead of the array of results.
# --hints--
You should create a `displayBooks` function.
Your `getBookInformation` function should return a string.
```js
assert.isFunction(displayBooks)
assert.isString(getBookInformation(library));
```
Your `displayBooks` function should have one parameter.
Your `getBookInformation` function should return a single string representing the final result.
```js
assert.lengthOf(displayBooks, 1)
```
Your `displayBooks` function should use a higher order function. Ex. (`filter`, `map`, `reduce`)
```js
assert.match(displayBooks.toString(), /filter|map|reduce|forEach/);
```
Your `displayBooks` function should return a string.
```js
assert.isString(displayBooks(library))
```
Your `displayBooks` function should return each book title, author and number of pages, for all books in the array passed to it.
```js
const libraryBooks = displayBooks(library);
library.forEach((book) => {
assert.include(libraryBooks, book.title);
assert.include(libraryBooks, book.author);
assert.include(libraryBooks, book.pages.toString());
});
const _differentLibrary = [
const testLibrary = [
{
title: 'Title A',
author: 'Author A',
about: 'About A',
title: "Title A",
author: "Author A",
about: "About A",
pages: 320,
},
{
title: 'Title B',
author: 'Author B',
about: 'About B',
title: "Title B",
author: "Author B",
about: "About B",
pages: 320,
},
{
title: 'Title C',
author: 'Author C',
about: 'About C',
title: "Title C",
author: "Author C",
about: "About C",
pages: 304,
},
];
const _differentBooks = displayBooks(_differentLibrary);
_differentLibrary.forEach((book) => {
assert.include(_differentBooks, book.title);
assert.include(_differentBooks, book.author);
assert.include(_differentBooks, book.pages.toString());
});
const expected = `Title A by Author A
Title B by Author B
Title C by Author C`;
assert.strictEqual(getBookInformation(testLibrary), expected);
```
# --seed--
@ -134,7 +123,13 @@ const library = [
},
];
console.log("Books in the Library:\n");
--fcc-editable-region--
function getBookInformation(catalog) {
return catalog.map(book => `${book.title} by ${book.author}`)
}
--fcc-editable-region--
console.log(getBookInformation(library));
```

View File

@ -0,0 +1,90 @@
---
id: 682264d807fe00058c1ea013
title: Step 10
challengeType: 1
dashedName: step-10
---
# --description--
For the next part of the workshop, you will focus on displaying a list of book summaries to the console.
Begin by logging the message `"\nList of book summaries:\n"` to the console. The newline character is added here because there should be a space before and after the message here.
# --hints--
You should log the message `"\nList of book summaries:\n"` to the console.
```js
assert.match(code, /console\.log\(("|')\\nList\s+of\s+book\s+summaries:\\n\1\);?/);
```
# --seed--
## --seed-contents--
```js
const library = [
{
title: 'Your Next Five Moves: Master the Art of Business Strategy',
author: 'Patrick Bet-David and Greg Dinkin',
about: 'A book on how to plan ahead',
pages: 320,
},
{
title: 'Atomic Habits',
author: 'James Clear',
about: 'A practical book about discarding bad habits and building good ones',
pages: 320,
},
{
title: 'Choose Your Enemies Wisely: Business Planning for the Audacious Few',
author: 'Patrick Bet-David',
about:
"A book that emphasizes the importance of identifying and understanding one's adversaries to succeed in the business world",
pages: 304,
},
{
title: 'The Embedded Entrepreneur',
author: 'Arvid Kahl',
about: 'A book focusing on how to build an audience-driven business',
pages: 308,
},
{
title: 'How to Be a Coffee Bean: 111 Life-Changing Ways to Create Positive Change',
author: 'Jon Gordon',
about: 'A book about effective ways to lead a coffee bean lifestyle',
pages: 256,
},
{
title: 'The Creative Mindset: Mastering the Six Skills That Empower Innovation',
author: 'Jeff DeGraff and Staney DeGraff',
about: 'A book on how to develop creativity and innovation skills',
pages: 168,
},
{
title: 'Rich Dad Poor Dad',
author: 'Robert Kiyosaki and Sharon Lechter',
about: 'A book about financial literacy, financial independence, and building wealth. ',
pages: 336,
},
{
title: 'Zero to Sold',
author: 'Arvid Kahl',
about: 'A book on how to bootstrap a business',
pages: 500,
},
];
console.log("Books in the Library:\n");
function getBookInformation(catalog) {
return catalog.map(book => `${book.title} by ${book.author}`).join("\n");
}
console.log(getBookInformation(library));
--fcc-editable-region--
--fcc-editable-region--
```

View File

@ -0,0 +1,136 @@
---
id: 6822694e3d34c807feeaba50
title: Step 12
challengeType: 1
dashedName: step-12
---
# --description--
Just like in a prior step, the desired result would look nicer as a string instead of an array.
Chain the `join()` method to your existing `map()` method and pass in `"\n"` for the separator to the `join()`.
Then, below your `getBookSummaries` function, add a `console.log()`. The `console` statement should call the `getBookSummaries` function with `library` for the argument.
Now, you should see a string for the result in the console.
# --hints--
Your `getBookSummaries` function should return a string.
```js
assert.isString(getBookSummaries(library));
```
Your `getBookSummaries` function should return a single string representing the final result.
```js
const testLibrary = [
{
title: "Title A",
author: "Author A",
about: "About A",
pages: 320,
},
{
title: "Title B",
author: "Author B",
about: "About B",
pages: 320,
},
{
title: "Title C",
author: "Author C",
about: "About C",
pages: 304,
},
];
const expected = `About A
About B
About C`;
assert.strictEqual(getBookSummaries(testLibrary), expected);
```
You should have a `console.log(getBookSummaries(library));` in your code.
```js
assert.match(code, /console\.log\(\s*getBookSummaries\(\s*library\s*\)\);?/gi);
```
# --seed--
## --seed-contents--
```js
const library = [
{
title: 'Your Next Five Moves: Master the Art of Business Strategy',
author: 'Patrick Bet-David and Greg Dinkin',
about: 'A book on how to plan ahead',
pages: 320,
},
{
title: 'Atomic Habits',
author: 'James Clear',
about: 'A practical book about discarding bad habits and building good ones',
pages: 320,
},
{
title: 'Choose Your Enemies Wisely: Business Planning for the Audacious Few',
author: 'Patrick Bet-David',
about:
"A book that emphasizes the importance of identifying and understanding one's adversaries to succeed in the business world",
pages: 304,
},
{
title: 'The Embedded Entrepreneur',
author: 'Arvid Kahl',
about: 'A book focusing on how to build an audience-driven business',
pages: 308,
},
{
title: 'How to Be a Coffee Bean: 111 Life-Changing Ways to Create Positive Change',
author: 'Jon Gordon',
about: 'A book about effective ways to lead a coffee bean lifestyle',
pages: 256,
},
{
title: 'The Creative Mindset: Mastering the Six Skills That Empower Innovation',
author: 'Jeff DeGraff and Staney DeGraff',
about: 'A book on how to develop creativity and innovation skills',
pages: 168,
},
{
title: 'Rich Dad Poor Dad',
author: 'Robert Kiyosaki and Sharon Lechter',
about: 'A book about financial literacy, financial independence, and building wealth. ',
pages: 336,
},
{
title: 'Zero to Sold',
author: 'Arvid Kahl',
about: 'A book on how to bootstrap a business',
pages: 500,
},
];
console.log("Books in the Library:\n");
function getBookInformation(catalog) {
return catalog.map(book => `${book.title} by ${book.author}`).join("\n");
}
console.log(getBookInformation(library));
console.log("\nList of book summaries:\n");
--fcc-editable-region--
function getBookSummaries(catalog) {
return catalog.map((book) => book.about)
}
--fcc-editable-region--
```

View File

@ -0,0 +1,98 @@
---
id: 68226c92f138dd09cd5b9722
title: Step 13
challengeType: 1
dashedName: step-13
---
# --description--
For this next part of the workshop, you are going to learn how to display a list of books by author.
Begin by logging the message `"\nList of books by Arvid Kahl:\n"` to the console.
# --hints--
You should log the message `"\nList of books by Arvid Kahl:\n"` to the console.
```js
assert.match(code, /console\.log\(("|')\\nList\s+of\s+books\s+by\s+Arvid\s+Kahl:\\n\1\);?/);
```
# --seed--
## --seed-contents--
```js
const library = [
{
title: 'Your Next Five Moves: Master the Art of Business Strategy',
author: 'Patrick Bet-David and Greg Dinkin',
about: 'A book on how to plan ahead',
pages: 320,
},
{
title: 'Atomic Habits',
author: 'James Clear',
about: 'A practical book about discarding bad habits and building good ones',
pages: 320,
},
{
title: 'Choose Your Enemies Wisely: Business Planning for the Audacious Few',
author: 'Patrick Bet-David',
about:
"A book that emphasizes the importance of identifying and understanding one's adversaries to succeed in the business world",
pages: 304,
},
{
title: 'The Embedded Entrepreneur',
author: 'Arvid Kahl',
about: 'A book focusing on how to build an audience-driven business',
pages: 308,
},
{
title: 'How to Be a Coffee Bean: 111 Life-Changing Ways to Create Positive Change',
author: 'Jon Gordon',
about: 'A book about effective ways to lead a coffee bean lifestyle',
pages: 256,
},
{
title: 'The Creative Mindset: Mastering the Six Skills That Empower Innovation',
author: 'Jeff DeGraff and Staney DeGraff',
about: 'A book on how to develop creativity and innovation skills',
pages: 168,
},
{
title: 'Rich Dad Poor Dad',
author: 'Robert Kiyosaki and Sharon Lechter',
about: 'A book about financial literacy, financial independence, and building wealth. ',
pages: 336,
},
{
title: 'Zero to Sold',
author: 'Arvid Kahl',
about: 'A book on how to bootstrap a business',
pages: 500,
},
];
console.log("Books in the Library:\n");
function getBookInformation(catalog) {
return catalog.map(book => `${book.title} by ${book.author}`).join("\n");
}
console.log(getBookInformation(library));
console.log("\nList of book summaries:\n");
function getBookSummaries(catalog) {
return catalog.map((book) => book.about).join("\n");
}
console.log(getBookSummaries(library));
--fcc-editable-region--
--fcc-editable-region--
```

View File

@ -0,0 +1,108 @@
---
id: 682277e2d3a05f0c5cf34d19
title: Step 15
challengeType: 1
dashedName: step-15
---
# --description--
Now, it is time to test out your function.
Add a `console.log()` below your `getBooksByAuthor()` function.
Inside the `console.log()`, call the `getBooksByAuthor()` function with `library` and `"Arvid Kahl"` for arguments.
Now, you should see all of the books for that particular author in the console.
# --hints--
You should have a `console.log(getBooksByAuthor(library, "Arvid Kahl"))`.
```js
assert.match(code, /console\.log\(\s*getBooksByAuthor\s*\(\s*library\s*,\s*(['"])\s*Arvid\s+Kahl\s*\1\s*\)\s*\)/);
```
# --seed--
## --seed-contents--
```js
const library = [
{
title: 'Your Next Five Moves: Master the Art of Business Strategy',
author: 'Patrick Bet-David and Greg Dinkin',
about: 'A book on how to plan ahead',
pages: 320,
},
{
title: 'Atomic Habits',
author: 'James Clear',
about: 'A practical book about discarding bad habits and building good ones',
pages: 320,
},
{
title: 'Choose Your Enemies Wisely: Business Planning for the Audacious Few',
author: 'Patrick Bet-David',
about:
"A book that emphasizes the importance of identifying and understanding one's adversaries to succeed in the business world",
pages: 304,
},
{
title: 'The Embedded Entrepreneur',
author: 'Arvid Kahl',
about: 'A book focusing on how to build an audience-driven business',
pages: 308,
},
{
title: 'How to Be a Coffee Bean: 111 Life-Changing Ways to Create Positive Change',
author: 'Jon Gordon',
about: 'A book about effective ways to lead a coffee bean lifestyle',
pages: 256,
},
{
title: 'The Creative Mindset: Mastering the Six Skills That Empower Innovation',
author: 'Jeff DeGraff and Staney DeGraff',
about: 'A book on how to develop creativity and innovation skills',
pages: 168,
},
{
title: 'Rich Dad Poor Dad',
author: 'Robert Kiyosaki and Sharon Lechter',
about: 'A book about financial literacy, financial independence, and building wealth. ',
pages: 336,
},
{
title: 'Zero to Sold',
author: 'Arvid Kahl',
about: 'A book on how to bootstrap a business',
pages: 500,
},
];
console.log("Books in the Library:\n");
function getBookInformation(catalog) {
return catalog.map(book => `${book.title} by ${book.author}`).join("\n");
}
console.log(getBookInformation(library));
console.log("\nList of book summaries:\n");
function getBookSummaries(catalog) {
return catalog.map((book) => book.about).join("\n");
}
console.log(getBookSummaries(library));
console.log("\nList of books by Arvid Kahl:\n");
function getBooksByAuthor(catalog, author) {
return catalog.filter((book) => book.author === author);
}
--fcc-editable-region--
--fcc-editable-region--
```

View File

@ -0,0 +1,116 @@
---
id: 6827deed7fc01f074c90fc0d
title: Step 16
challengeType: 1
dashedName: step-16
---
# --description--
It would be nice to test our your `getBooksByAuthor` function with another author.
Begin by logging the message `"\nList of books by James Clear:\n"` to the console.
Below that `console.log()`, add another `console.log()`. Inside that `console.log()`, call the `getBooksByAuthor()` function with `library` and `"James Clear"` for arguments.
Now, you should see all of the books for that particular author in the console.
# --hints--
You should log the message `"\nList of books by James Clear:\n"` to the console.
```js
assert.match(code, /console\.log\(("|')\\nList\s+of\s+books\s+by\s+James\s+Clear:\\n\1\);?/);
```
You should have a `console.log(getBooksByAuthor(library, "James Clear"))`.
```js
assert.match(code, /console\.log\(\s*getBooksByAuthor\s*\(\s*library\s*,\s*(['"])\s*James\s+Clear\s*\1\s*\)\s*\)/);
```
# --seed--
## --seed-contents--
```js
const library = [
{
title: 'Your Next Five Moves: Master the Art of Business Strategy',
author: 'Patrick Bet-David and Greg Dinkin',
about: 'A book on how to plan ahead',
pages: 320,
},
{
title: 'Atomic Habits',
author: 'James Clear',
about: 'A practical book about discarding bad habits and building good ones',
pages: 320,
},
{
title: 'Choose Your Enemies Wisely: Business Planning for the Audacious Few',
author: 'Patrick Bet-David',
about:
"A book that emphasizes the importance of identifying and understanding one's adversaries to succeed in the business world",
pages: 304,
},
{
title: 'The Embedded Entrepreneur',
author: 'Arvid Kahl',
about: 'A book focusing on how to build an audience-driven business',
pages: 308,
},
{
title: 'How to Be a Coffee Bean: 111 Life-Changing Ways to Create Positive Change',
author: 'Jon Gordon',
about: 'A book about effective ways to lead a coffee bean lifestyle',
pages: 256,
},
{
title: 'The Creative Mindset: Mastering the Six Skills That Empower Innovation',
author: 'Jeff DeGraff and Staney DeGraff',
about: 'A book on how to develop creativity and innovation skills',
pages: 168,
},
{
title: 'Rich Dad Poor Dad',
author: 'Robert Kiyosaki and Sharon Lechter',
about: 'A book about financial literacy, financial independence, and building wealth. ',
pages: 336,
},
{
title: 'Zero to Sold',
author: 'Arvid Kahl',
about: 'A book on how to bootstrap a business',
pages: 500,
},
];
console.log("Books in the Library:\n");
function getBookInformation(catalog) {
return catalog.map(book => `${book.title} by ${book.author}`).join("\n");
}
console.log(getBookInformation(library));
console.log("\nList of book summaries:\n");
function getBookSummaries(catalog) {
return catalog.map((book) => book.about).join("\n");
}
console.log(getBookSummaries(library));
console.log("\nList of books by Arvid Kahl:\n");
function getBooksByAuthor(catalog, author) {
return catalog.filter((book) => book.author === author);
}
console.log(getBooksByAuthor(library, "Arvid Kahl"));
--fcc-editable-region--
--fcc-editable-region--
```

View File

@ -0,0 +1,109 @@
---
id: 6827e10547fdd308bca1c73d
title: Step 17
challengeType: 1
dashedName: step-17
---
# --description--
For the last part of the workshop, you will learn how to get the total number of pages for all of the books in the library.
Start by logging to the message `"\nTotal number of pages for all library books:\n"` to the console.
# --hints--
You should log the message `"\nTotal number of pages for all library books:\n"` to the console.
```js
assert.match(code, /console\.log\((["'])\\nTotal\s+number\s+of\s+pages\s+for\s+all\s+library\s+books:\\n\1\);?/);
```
# --seed--
## --seed-contents--
```js
const library = [
{
title: 'Your Next Five Moves: Master the Art of Business Strategy',
author: 'Patrick Bet-David and Greg Dinkin',
about: 'A book on how to plan ahead',
pages: 320,
},
{
title: 'Atomic Habits',
author: 'James Clear',
about: 'A practical book about discarding bad habits and building good ones',
pages: 320,
},
{
title: 'Choose Your Enemies Wisely: Business Planning for the Audacious Few',
author: 'Patrick Bet-David',
about:
"A book that emphasizes the importance of identifying and understanding one's adversaries to succeed in the business world",
pages: 304,
},
{
title: 'The Embedded Entrepreneur',
author: 'Arvid Kahl',
about: 'A book focusing on how to build an audience-driven business',
pages: 308,
},
{
title: 'How to Be a Coffee Bean: 111 Life-Changing Ways to Create Positive Change',
author: 'Jon Gordon',
about: 'A book about effective ways to lead a coffee bean lifestyle',
pages: 256,
},
{
title: 'The Creative Mindset: Mastering the Six Skills That Empower Innovation',
author: 'Jeff DeGraff and Staney DeGraff',
about: 'A book on how to develop creativity and innovation skills',
pages: 168,
},
{
title: 'Rich Dad Poor Dad',
author: 'Robert Kiyosaki and Sharon Lechter',
about: 'A book about financial literacy, financial independence, and building wealth. ',
pages: 336,
},
{
title: 'Zero to Sold',
author: 'Arvid Kahl',
about: 'A book on how to bootstrap a business',
pages: 500,
},
];
console.log("Books in the Library:\n");
function getBookInformation(catalog) {
return catalog.map(book => `${book.title} by ${book.author}`).join("\n");
}
console.log(getBookInformation(library));
console.log("\nList of book summaries:\n");
function getBookSummaries(catalog) {
return catalog.map((book) => book.about).join("\n");
}
console.log(getBookSummaries(library));
console.log("\nList of books by Arvid Kahl:\n");
function getBooksByAuthor(catalog, author) {
return catalog.filter((book) => book.author === author);
}
console.log(getBooksByAuthor(library, "Arvid Kahl"));
console.log("\nList of books by James Clear:\n");
console.log(getBooksByAuthor(library, "James Clear"));
--fcc-editable-region--
--fcc-editable-region--
```