enum Category { Biography, // 0 Poetry, // 1 Fiction, // 2 } function GetAllBooks() { let books = [ { author: 'James Joyce', available: true, category: Category.Fiction, id: 1, title: 'Ulysses', }, { author: 'Ernest Hemingway', available: false, category: Category.Fiction, id: 2, title: 'A farewall to arms', }, { author: 'Maya Angelou', available: true, category: Category.Poetry, id: 3, title: 'I know why the caged bird sings', }, { author: 'Herman Melville', available: true, category: Category.Fiction, id: 4, title: 'Moby Dick', } ]; return books; } function LogFirstAvailable(books): void { const numberOfBooks: number = books.length; let firstAvailable: string = ''; for (let currentBook of books) { if (currentBook.available) { firstAvailable = currentBook.title; break; } } console.log(`Total number of books: ${numberOfBooks}.`); console.log(`First available: ${firstAvailable}.`); } function CreateCustomerId(name: string, id: number): string { return name + id; } function GetBookTitlesByCategory(categoryFilter: Category): Array { console.log(`Getting books in category: ${Category[categoryFilter]}.`); const allBooks = GetAllBooks(); const filteredTitles: string[] = []; for (let currentBook of allBooks) { if (currentBook.category === categoryFilter) { filteredTitles.push(currentBook.title); } } return filteredTitles; } function GetBookById(id: number) { const allBooks = GetAllBooks(); return allBooks.filter(book => book.id === id)[0]; } function LogBookTitles(titles: string[]): void { for (let title of titles) { console.log(title); } } //****************************************************************************** let x: number; let idGenerator: (chars: string, nums: number) => string; idGenerator = CreateCustomerId; let myID: string = idGenerator('Daniel', 10); console.log(myID); idGenerator = (name, id) => id + name; myID = idGenerator('Daniel', 10); console.log(myID); // const fictionBookTitles = GetBookTitlesByCategory(Category.Fiction); // fictionBookTitles.forEach((val, idx, arr) => console.log(`${++idx} ${val}.`));