|
@@ -10,24 +10,28 @@ function GetAllBooks() {
|
|
author: 'James Joyce',
|
|
author: 'James Joyce',
|
|
available: true,
|
|
available: true,
|
|
category: Category.Fiction,
|
|
category: Category.Fiction,
|
|
|
|
+ id: 1,
|
|
title: 'Ulysses',
|
|
title: 'Ulysses',
|
|
},
|
|
},
|
|
{
|
|
{
|
|
author: 'Ernest Hemingway',
|
|
author: 'Ernest Hemingway',
|
|
available: false,
|
|
available: false,
|
|
category: Category.Fiction,
|
|
category: Category.Fiction,
|
|
|
|
+ id: 2,
|
|
title: 'A farewall to arms',
|
|
title: 'A farewall to arms',
|
|
},
|
|
},
|
|
{
|
|
{
|
|
author: 'Maya Angelou',
|
|
author: 'Maya Angelou',
|
|
available: true,
|
|
available: true,
|
|
category: Category.Poetry,
|
|
category: Category.Poetry,
|
|
|
|
+ id: 3,
|
|
title: 'I know why the caged bird sings',
|
|
title: 'I know why the caged bird sings',
|
|
},
|
|
},
|
|
{
|
|
{
|
|
author: 'Herman Melville',
|
|
author: 'Herman Melville',
|
|
available: true,
|
|
available: true,
|
|
category: Category.Fiction,
|
|
category: Category.Fiction,
|
|
|
|
+ id: 4,
|
|
title: 'Moby Dick',
|
|
title: 'Moby Dick',
|
|
}
|
|
}
|
|
];
|
|
];
|
|
@@ -64,11 +68,21 @@ function GetBookTitlesByCategory(categoryFilter: Category): Array<string> {
|
|
return filteredTitles;
|
|
return filteredTitles;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+function GetBookById(id: number) {
|
|
|
|
+ const allBooks = GetAllBooks();
|
|
|
|
+ return allBooks.filter(book => book.id === id)[0];
|
|
|
|
+}
|
|
|
|
+
|
|
function LogBookTitles(titles: string[]): void {
|
|
function LogBookTitles(titles: string[]): void {
|
|
for (let title of titles) {
|
|
for (let title of titles) {
|
|
console.log(title);
|
|
console.log(title);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-const poetryBooks = GetBookTitlesByCategory(Category.Poetry);
|
|
|
|
-LogBookTitles(poetryBooks);
|
|
|
|
|
|
+//******************************************************************************
|
|
|
|
+
|
|
|
|
+const fictionBookTitles = GetBookTitlesByCategory(Category.Fiction);
|
|
|
|
+// LogBookTitles(fictionBookTitles);
|
|
|
|
+fictionBookTitles.forEach((val, idx, arr) => console.log(`${++idx} ${val}.`));
|
|
|
|
+
|
|
|
|
+console.log(GetBookById(2));
|