1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- function GetAllBooks() {
- let books = [
- {
- author: 'James Joyce',
- available: true,
- title: 'Ulysses',
- },
- {
- author: 'Ernest Hemingway',
- available: false,
- title: 'A farewall to arms',
- },
- {
- author: 'Maya Angelou',
- available: true,
- title: 'I know why the caged bird sings',
- },
- {
- author: 'Herman Melville',
- available: true,
- 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}.`);
- }
- const allBooks = GetAllBooks();
- LogFirstAvailable(allBooks);
|